0

My XML

<catalog>
<item Id="1">
<book id="b1">
</book>
<cd id="c1">
</cd>
</item>

<item Id="11">
<book id="b11">
</book>
<cd id="c11">
</cd>
</item>
</catalog>

what I have ..

ap.selectXPath("/catalog/item");
while ((result = ap.evalXPath()) != -1) {
if (vn.toElement(VTDNav.FIRST_CHILD, "item")) {
do {
//do something with the contnets in the item node 
} while (vn.toElement(VTDNav.NEXT_SIBLING, "book"));
}

// move to the parent node to traverse the rest of the items }

What I want is to get to the "cd" node.

In some of the examples I saw VTDNav.NEXT_CHILD but seems like is not available . Can anyone suggest how to get to the node I need to . For now I am managing to do it by getting to the FIRST_CHILD and then moving to the next sibling

if (vn.toElement(VTDNav.FIRST_CHILD, "book")) {
                    // Move to the next sibling 
                    vn.toElement(VTDNav.NEXT_SIBLING, "cd");

                }

Appreciate all your help

Regards

Chansdad
  • 120
  • 2
  • 4
  • it is a legit question, why is there a negative vote? – vtd-xml-author Oct 15 '14 at 06:40
  • you don't need next sibling, this is the same behavior as DOM – vtd-xml-author Oct 15 '14 at 06:41
  • Realized it as down voted .. not sure why. But either way can you clarify what you mean by same behavior as DOM .. In my XML i have a bunch of Items , and then under each Item I have books and CD's and for each of these book and cd's there are a bunch of nodes . In first pass I am processing all books , next pass my cursor is at the root and iam ready to process the CD's .. any code snippet will be a great help . After looking at various parsers and options to parse xml files i settled on VTD XML.. just perfect for what I am doing . Processing verylarge number of xml files of several megs – Chansdad Oct 15 '14 at 15:01
  • next_child is not a meaning full parameter for navigation because there seems to be a first child before next child becomes meaningful, doesn't it? – vtd-xml-author Oct 18 '14 at 01:03

1 Answers1

0

You should not need to have next child. What you look for is probably NEXT_SIBLING, after you call FIRST_CHILD...

vtd-xml-author
  • 3,319
  • 4
  • 22
  • 30