I’m making a simple drawing program with slides in it and I have an XML file with the following schema:
For every slide, I store a line or multiple line segments such as:
http://orhancanceylan.com/stack/file.xml
I’m taking “Slides” with this code:
NodeList nodeLst = doc.getElementsByTagName("Slide");
System.out.println(nodeLst.getLength());
And iterate by taking nodes:
Node fstNode = nodeLst.item(i);
But in my iteration, I couldn’t figure out how I should take the line segment or lines only for the first node(first slide).
How should I parse these XML properly?
Thanks.
Perhaps you could consider using XPath to do the dirty work of looking up your XML nodes:
http://download.oracle.com/javase/6/docs/api/javax/xml/xpath/package-summary.html
To get just the segment from the first slide, the XPath could be:
//Slide[id='0']/segmentFor example, maybe something like this:
Then evaluate your doc with the given XPath expression, and typecast the resulte:
That will give you just the first slide’s
<segment>node in your XML. You can probably extrapolate from that answer on how to get more XML nodes using XPath. See http://www.ibm.com/developerworks/library/x-javaxpathapi/index.html