質問

I'm building a VTD based XML Parsing engine in order to process files from several input systems.

I'm currently trying to get values from tags with namespace prefix:

<?xml version="1.0" encoding="UTF-8"?>
 <cli:clients xmlns declarations >
<cli:client>
    <dat:name>CLIENT NAME</dat:name>
    <dat:age>1</dat:age>
</cli:client>

and querying the following Xpaths:

//client/age/text()
//client/name/text()

How can I set VTD AutoPilot to ignore the namespace prefix?

NOTE: I cannot change the xpaths as I already have this engine in production implemented with JDK's default xpath engine.

UPDATE: See below the code I am using to test. File is similar to the one on the top:

@Test
public void doFile() throws Exception {
    byte[] xmlData = FileUtils.loadFile("namespace-test.xml");
    VTDGen gen = new VTDGen();
    gen.setDoc(xmlData);
    gen.parse(false);
    VTDNav vtd = gen.getNav();
    AutoPilot pilot = new AutoPilot(vtd);
    pilot.selectXPath("//clients");
    int re = pilot.evalXPath();
    System.out.println(re);
    if (re >= 0) {
        System.out.println(vtd.toString(re));
    }
}
役に立ちましたか?

解決

As per @vtd-xml-author comments, I got the newest version of VTDNav.java file and compiled on my own project.

The solution worked on the first try!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top