java - XML namespace defaulting/inheritance -
What are the namespaces of a, c, d and e in the XML snippet given below? The references to the documentation or specifications will be appreciated.
& lt; A xmlns = "http: // domain / a" & gt; & Lt; Pre: b xmlns: pre = "http: // domain / b" & gt; & Lt; C / & gt; & Lt; D xmlns = "" & gt; & Lt; E / & gt; & Lt; / D & gt; & Lt; / East: p & gt; & Lt; / A & gt;
In addition, do the Java framework respect the exchange of official namespace? Me tride org.w2c * DOM packages, although this namespace does not seem to solve the URI correctly? For example, something with the same functionality.
String namespace = DocumentPerpers. PRSE () GetElement ("A"). GetElement ("B"). GetElement ("C"). GetNamespaceURI (); To make the best of my knowledge, Java support namespaces have all the standard XML APIs. I
Many APIs were written before or after namespace creation (or became popular - I can not remember now). You often need it:
Public class ns {Private static zero print (node node) {Q < Node & gt; Nodes = new linked list & lt; Node & gt; (); Nodes.add (node); While (! Nodes.isEmpty ()) {node = nodes.poll (); Node list list = node.gate childnode (); (Int i = 0; i & lt; list.getLength (); i ++) {nodes.add (list.item (i)) for; } System.out.format ("% s% s% s% n", node.getPrefix (), node .getLocalName (), node.gatnamepaceURI ()); }} Public static zero principal (string [] args) exception {string xml = "& lt; a xmlns = \" http: // domain / a \ "& gt; +" & lt; Pre: b xmlns: pre = \ "http: // domain / b \" & gt; "+" & lt; C /> "+" & lt; D xmlns = \ "\" & gt; "+" & lt; E / & gt; "+" & lt; / D> "+" & lt; / Pre: b & gt; "+" & lt; / A & gt; "; DocumentBuilderFactory DBF = DocumentBuilderFactory.newInstance (); dbf.setNamespaceAware (true); Document Doctor = dbf.newDocumentBuilder () .pars (new input source (new stringreader (XML)); print (doc. GetDocumentElement ());}}
This code will print:
Tap one http: // domain / abb http: // domain / b null C http: // domain / a null de tap faucet a null
Comments
Post a Comment