I have the following XML File:
<project>
<category type="Files">
<type name="File" type="String" id="1">
<field name="Name" type="String">
<value type="String"><![CDATA[Smile.JPG]]></value>
</field>
<multiValue name="Entries" type="FileEntry">
<model type="Specs" state="Intact">
<field name="Value" type="String">
<value type="String"><![CDATA[10241624]]></value>
</field>
</model>
</multiValue>
</type>
<type name="File" type="String" id="2">
<field name="Name" type="String">
<value type="String"><![CDATA[OldMan.JPG]]></value>
</field>
<multiValue name="Entries" type="FileEntry">
<model type="Specs" state="Gone">
<field name="Category" type="String">
<value type="String"><![CDATA[Size]]></value>
</field>
<field name="Value" type="String">
<value type="String"><![CDATA[821563412]]></value>
</field>
</model>
</multiValue>
</type>
</category>
</project>
java code snippet: (Just the code to isolate the issue)
VTDGen vg = new VTDGen();
int i;
AutoPilot ap = new AutoPilot();
ap.selectXPath("/project/category[@type=\"Files\"]");
AutoPilot ap2 = new AutoPilot();
BookMark bm = new BookMark();
vg.parseFile("stackoverflow_example.xml", false);
VTDNav vn = vg.getNav();
ap.bind(vn);
ap2.bind(vn);
/* main XPath selection */
ap.selectXPath("/project/category[@type=\"Files\"]");
/* part 1 */
//XPath eval returns one node at a time
ap2.selectXPath("type[@name=\"File\"]/field/value/text()");
while ((i = ap.evalXPath()) != -1) {
bm.recordCursorPosition(); // equivalent to vn.push();
int j;
while ((j = ap2.evalXPath()) != -1) {
logger.debug(" NAME ==> " + vn.toString(j));
}
ap2.resetXPath();
bm.setCursorPosition(); // equivalent to vn.pop();
}
ap.resetXPath();
/* part 2 */
ap2.selectXPath("type[@name=\"File\"]/multiValue/model[@type=\"Specs\"]/field[@name=\"Value\"]/value/text()");
while ((i = ap.evalXPath()) != -1) {
bm.recordCursorPosition(); // equivalent to vn.push();
int j;
while ((j = ap2.evalXPath()) != -1) {
logger.debug(" SIZE ==> " + vn.toString(j));
}
ap2.resetXPath();
bm.setCursorPosition(); // equivalent to vn.pop();
}
ap.resetXPath();
And after finding one section of the type with the name File, I want to get the filename and size from this section. (Of course, later on a bit more, but for my understanding, this would be sufficient).
The problem with the code is now, that it does find the matching values, but the SIZE is not a child from the File.
Output:
NAME ==> Smile.JPG
NAME ==> OldMan.JPG
SIZE ==> 10241624
SIZE ==> 821563412
I have two AutoPilots, one for the main section and I had the idea to inner-search with the second AutoPilot.
Can anybody help only "search" in the first found section? I would like to have some output like:
NAME ==> Smile.JPG
SIZE ==> 10241624
NAME ==> OldMan.JPG
SIZE ==> 821563412