Why is there no prefix associated with this xmlns?
I'm playing around with XMPP and thus learning about XML. Here is an example of an element to retrieve all registered users from the XMPP docs:
<iq firstname.lastname@example.org/globe' id='get-registered-users-num-1' to='shakespeare.lit' type='set' xml:lang='en'> <command xmlns='http://jabber.org/protocol/commands' action='execute' node='http://jabber.org/protocol/admin#get-registered-users-num'/> </iq>
Why is there no prefix before the xmlns namespace? Why is it not:
<command xmlns=get_users:'http://jabber.org/protocol/commands' action='execute' node='http://jabber.org/protocol/admin#get-registered-users-num'/>
Does this mean it's defining a namespace for this one child element <command> only? If so, why do that?
This is what is referred to as the 'default' namespace. It, essentially, prefixes all attributes (and elements) of the element it is declared on with that namespace (which, in this case is http://jabber.org/protocol/commands), making it equivalent to this:
<command xmlns:default_namespace="http://jabber.org/protocol/commands" default_namespace:action="execute" default_namespace:node="http://jabber.org/protocol/admin#get-registered-users-num" />
If you were to have children of that node, they would also have that same default namespace prefixed to them automatically as well (unless they themselves had a different default namespace).
It's pretty handy if you're only dealing with one namespace, but things can go out of hand rather fast if you're dealing with multiples.
xPath can sometimes have issues with default namespaces as well, so if you are using that to parse your XML, beware!