VTD-XML:如何获取当前元素的XPath?

时间:2015-08-01 08:28:12

标签: xml xpath vtd-xml

我正在使用VTD来解析和分割非常大的XML文件,并且在调用AutoPilot.evalXPath()之后需要光标指向的当前元素的实际XPath。

考虑以下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>

我正在使用AutoPilot

初始化autopilot.selectXPath("/atlas/continents/continent/countries/country");

当我使用autopilot.evalXPath()迭代匹配时,我需要每个元素的绝对XPath,例如像/atlast/continents/continent[1]/countries/country[2]

我在VTDNavAutoPilot -

中尝试了几乎所有方法
  • VTDNav.getXPathStringVal() / VTDNav.getXPathStringVal(short mode)
  • VTDNav.toNormalizedXPathString(int j)
  • AutoPilot.getExprString()

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我不认为vtd在当前版本中提供了一个功能,事实上我并不知道任何提供此功能的api。我认为原因是任何当前元素节点都有许多不同的可能的XPath ......你怎么看?

相关问题