I am trying to read an XML file, for example:
I should be enabled I have set up my XML reader so that I have: But this method I can simply change the I'll call those Instead of using XPath makes it all very easy: & lt; Item & gt;
getTextContent () for each title, description, etc. for the tag a
& lt; Title & gt; tag is one such
& lt; Item & gt; is not a child with the tag that I do not want
getTextContent () .
document doc = dbuilder.parse (xmlFile); Doc.getDocumentElement () Normal () .; String title = document.getElementsByTagName ("title"). Items (0) .getTextContent ();
& lt; Title & gt; which is
& lt; Item & gt;
object (0) to
object (1) , but I need this algorithm so that the different Can be worked with XML files which are not the initial
and lieutenant; without
& lt; Title & gt;
& lt; Item & gt; s
XPathFactory xpf = XPathFactory.newInstance (); XPath xp = xpf.newXPath (); Node list nl = (nodelist) xp.evaluate ("// items / title / text ()", doctor, XPathConstants.NODESET); For (int i = 0; i & lt; nl.getLength (); ++ i) {System.out.println (nl.item (i) .getNodeValue ()); }
No comments:
Post a Comment