xml parsing - How to get tagname of a TEXT_NODE in java's org.w3c.dom.Node -
in documentation interface states textnodes return "#text" names instead of actual tag name. i'm doing, tag name necessary.
// i'm using following imports import javax.xml.parsers.documentbuilder; import javax.xml.parsers.documentbuilderfactory; import org.w3c.dom.document; import org.w3c.dom.namednodemap; import org.w3c.dom.node; import org.w3c.dom.nodelist; import org.xml.sax.entityresolver; import org.xml.sax.inputsource; // in .xml input file <country>us</country> // "text node" .gettextcontent() // returns "us", need "country" , .getnodename() // returns "#text"
how access tag name? must possible somehow, don't mind hackish solution.
docs:
http://www.w3schools.com/dom/dom_nodetype.asp
http://www.w3.org/2003/01/dom2-javadoc/org/w3c/dom/node.html
thank you.
i think you've misunderstood nodes involved. xml:
<country>us</country>
... contains two nodes:
- the
country
element - the text node, content of us
the element not text node, , text node doesn't have element name, because it's not element. it's important understand these different nodes. that's source of confusion, believe.
if you're looking @ text node, use node.getparentnode().getnodename()
element name. or element node, call gettextcontent()
.
Comments
Post a Comment