1

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));
    }
}
vtd-xml-author
  • 3,319
  • 4
  • 22
  • 30
Mikhas
  • 851
  • 1
  • 12
  • 31
  • If you can't change the XPaths, then as we say in Boston, you're probably a young codfish -- ie, scrod. Normal recommendation would be to either add a prefix to the XPaths and tell the XPath engine which namespace that prefix is bound to, or (ugly, not recommended, but would work) to rewrite the XPath as wildcards with predicates explicitly testing only the localname. – keshlam Mar 13 '14 at 21:16
  • 2
    if you go on vtd-xml.sf.net and check out the latest vtdNav.java from cvs, you should have this working the same way as DOM... need more instructions – vtd-xml-author Mar 14 '14 at 08:11
  • 1
    @vtd-xml-author , is it working on the latest version of VTD-XML Java implementation ? I am using com.ximpleware:vtd-xml:2.11 (java version) – Mikhas Mar 14 '14 at 18:31
  • 2
    This is only available in 2.12, but you can have it right now by downloading it and then building a new tar file. – vtd-xml-author Mar 15 '14 at 05:56

1 Answers1

2

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!

Mikhas
  • 851
  • 1
  • 12
  • 31