问题
I'm using the following function to parse xml using VTD-XML:
final AutoPilot ap = new AutoPilot(vtdNav);
ap.selectXPath(path);
int i = -1;
/** evalXPath returns -1 if no new node is present */
while ((i = ap.evalXPath()) != -1) {
extractedValues.add(vtdNav.toString(i+1));
}
/** Reset the XPath */
ap.resetXPath();
But when I try to query :
<actualUnitCost>
<chargeOrAllowance>CHARGE</chargeOrAllowance>
<monetaryAmount currencyISOCode="USD">17.08</monetaryAmount>
</actualUnitCost>
using the path : /actualUnitCost/monetaryAmount it gives me the value as currencyISOCode instead of 17.08. How can I modify the query to get the desired result?
I've tried /actualUnitCost/monetaryAmount/text() but it doesn't yield the right answer.
回答1:
I think that is the correct behavior. If you try /actualUnitCost/monetaryAmount/text(), it will give you the text node.
Let me know if there is any question.
来源:https://stackoverflow.com/questions/56815624/vtd-xml-doesnt-return-the-right-value-how-can-i-modiy-the-query-to-get-the-rig