Java – VTD XML internal XPath expression
•
Java
I have an XML file like this
<root> <test> <bla>test1</bla> </test> <test> <bla>test2</bla> </test> <test> </test> </root>
Now I want to parse it using VTD XML parser by using an XPath expression First, I search for test tags
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("//test");
Now I want to search for the BLA tag in this test tag
int result = -1;
int count = 0;
while ((result = ap.evalXPath()) != -1) {
// evaluate XPath Expressions within the test tags
}
Can someone tell me how to make this expression? I don't want to search the whole document for BLA tags because I want to be able to assign BLA tags to test tags If the BLA tag is empty, I can't do this. I search for BLA tags throughout the document
Solution
You can declare another autopilot (shown below), although it is not always the easiest way
AutoPilot ap2 = new AutoPilot(); ap2.selectXPath("blah");
It is then nested in a loop
while ((result = ap.evalXPath()) != -1) {
// evaluate XPath Expressions within the test tags
int i2=-1;
while((i2=ap2.evalXPath())!=-1){
// do more stuff here
}
}
But the problem is that the second XPath needs to be a relative XPath expression
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
