Retrieving Namespace Information

Now that we've added namespace information to our elements, at some point we might want to get it back out again. Xerces provides for this possibility with the NamespaceSupport object. For example, we can analyze orderSystem and its two children, ord:orders and prod:products, with the code in Listing 6.20.

Listing 6.20. ReviewOrder.java: Retrieving Namespace Information
...
6:  import org.w3c.dom.Element;
6a: import org.w3c.dom.Node;
6b: import org.w3c.dom.NodeList;
6c: import org.w3c.dom.NamedNodeMap;
6d: import org.w3c.dom.Attr;
6e: import org.xml.sax.helpers.NamespaceSupport;
...
72:               processNode(nextNode, out, newParent, newDoc,
73:                                              namespaceURI, ns);
74:           }
75:       }
76:   }
77:
78: public void showNamespace(NamespaceSupport ...

Get XML and Java™ from scratch now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.