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 from='bard@shakespeare.lit/globe'
      <command xmlns='http://jabber.org/protocol/commands' 

Why is there no prefix before the xmlns namespace? Why is it not:

<command xmlns=get_users:'http://jabber.org/protocol/commands' 

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: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!

Need Your Help

LINQ Select Based on Another Select

c# linq

I always find myself stuck on LINQ in the same place. I simply cannot make LINQ techniques stick in my head.

Readding panel to layout after editing panel?

java layout awt panels

What I'm trying to do is dynamicly edit a panel and readd it to the (Border)layout. The panel contains textfields and I want the user to be able to add or remove textfields to the panel. What I tri...