2

I'm using VTD to parse and split very large XML files and require the actual XPath of the current element pointed to by the cursor after a call to AutoPilot.evalXPath().

Consider the following XML:

<atlas>
    <continents>
        <continent>
            <name>North America</name>
            <countries>
                <country>
                    <name>Canada</name>
                </country>
                <country>
                    <name>US</name>
                </country>
            </countries>
        </continent>
        <continent>
            <name>South America</name>
            <countries>
                <country>
                    <name>Chile</name>
                </country>
                <country>
                    <name>Brazil</name>
                </country>
            </countries>
        </continent>
    </continents>
</atlas>

I am initializing AutoPilot with autopilot.selectXPath("/atlas/continents/continent/countries/country");

As I iterate through the matches using autopilot.evalXPath(), I need the absolute XPath of each element, for example like /atlast/continents/continent[1]/countries/country[2].

I tried almost all methods in VTDNav and AutoPilot-

  • VTDNav.getXPathStringVal() / VTDNav.getXPathStringVal(short mode)
  • VTDNav.toNormalizedXPathString(int j)
  • AutoPilot.getExprString()

Any ideas?

lea
  • 21
  • 2

1 Answers1

0

I don't think vtd offers a function in the current release, in fact I am not aware of any api that offers this. I think the reason is that there are many different possible XPaths for any current element node... what do you think?

vtd-xml-author
  • 3,319
  • 4
  • 22
  • 30
  • Thanks for your reply @vtd-xml-author. Yes, there are many different XPaths to reach a node. And this capability does not seem to exist in other parsers like JDOM either. Not sure if I'm missing something here, but, doesn't every node have it's own unique absolute XPath? In my example above, `Canada` can be reached using several XPaths, but the absolute XPath `/atlast/continents/continent[0]/countries/country[0]` is unique to `Canada`. Seems simple enough, but I'm sure there's a lot more happening under the hood of the parser than I am able to imagine :) – lea Aug 04 '15 at 04:58
  • how bout /atlast/continents/continent[0]/countries/country[0]/../country[0]? – vtd-xml-author Aug 12 '15 at 04:21