Why are XML namespaces so hard to understand and use?
Actually, they aren’t. When trying to understand XML namespaces, all you need to do is remember one thing: • XML namespaces provide a two-part naming system for element types and attributes. That’s it. They don’t do anything else and what little complexity there is comes from the flexibility of declaration and scoping rules. You can minimize this complexity by doing the following: • Declare all XML namespaces on the root element. • Use one prefix per XML namespace. Processing XML namespaces isn’t that hard either. In a SAX 1.0 application, you can use John Cowan’s Namespace SAX Filter to return universal names; SAX 2.0 does this for you. In a DOM level 1 application, you can usually ask the DOM implementation for namespace information; DOM level 2 always provides this information. If you do your own processing, all you need to remember is to keep the prefix-to-URI mappings as part of your state, scan the attributes for xmlns attributes before doing anything else, and scan element type