4

I have a small test file when running with namespace huge fails. If I remove namespace both work am I doing something wrong with Huge code?

Changed to remove unworkable code

    try {
        //without namespace works
        VTDGen vtdGen = new VTDGen();
        vtdGen.parseFile("test.xml", false);
        VTDNav vtdNav = vtdGen.getNav();
        AutoPilot autoPilot = new AutoPilot(vtdNav);
        autoPilot.selectXPath("//Receiver/Identifier");
        autoPilot.evalXPath();
        System.out.println("Stand===>" + vtdNav.getXPathStringVal() + " ===>");
    } catch(IndexOutOfBoundsException e) {
        e.printStackTrace();
    }

    try {
        //with namespace doesn't work
        VTDGen vtdGen = new VTDGen();
        vtdGen.parseFile("test.xml", true);
        VTDNav vtdNav = vtdGen.getNav();
        AutoPilot autoPilot = new AutoPilot(vtdNav);
        autoPilot.declareXPathNameSpace("x", "http://test/namespaces/ssfgf");
        autoPilot.selectXPath("//x:Receiver/Identifier");
        int index = autoPilot.evalXPath();
        System.out.println("Stand NS ===>" + vtdNav.toString(index) + " ===>");
    } catch(IndexOutOfBoundsException e) {
        e.printStackTrace();
    }

    try {
        //without namespace doesn't work
        VTDGenHuge vg = new VTDGenHuge();
        vg.parseFile("test.xml", false);
        VTDNavHuge vn = vg.getNav();
        AutoPilotHuge ap = new AutoPilotHuge(vn);
        ap.selectXPath("//Receiver/Identifier");
        ap.evalXPath();
        System.out.println("Huge ===> " + vn.toString(vn.getText()) + " ===>");
    } catch(IndexOutOfBoundsException e) {
        e.printStackTrace();
    }

    try {
        //with namespace doesn't work
        VTDGenHuge vg = new VTDGenHuge();
        vg.parseFile("test.xml", true);
        VTDNavHuge vn = vg.getNav();
        AutoPilotHuge ap = new AutoPilotHuge(vn);
        ap.declareXPathNameSpace("x", "http://test/namespaces/ssfgf");
        ap.selectXPath("//Receiver/Identifier");
        ap.evalXPath();
        System.out.println("Huge NS ===> " + vn.toString(vn.getText()) + " ===>");
    } catch(IndexOutOfBoundsException e) {
        e.printStackTrace();
    }

I get java.lang.IndexOutOfBoundsException for both Huge code and standard with NS

This is the a sample XML unfortunately can't show real xml

<x:TestDocument xmlns:x="http://test/namespaces/ssfgf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://test/namespaces/ssfgf">
    <x:TestHeader>
        <x:Type></x:Type>
        <x:Scopes>
            <x:Scope>
                <x:Identifier>Context</x:Identifier>
                <x:Type>CaseId</x:Type>
                <x:InstanceIdentifier>case1</x:InstanceIdentifier>
                <x:Business>
                    <x:Name>businessnane1</x:Name>
                </x:Business>
            </x:Scope>
            <x:Scope>
                <x:Identifier>Context</x:Identifier>
                <x:InstanceIdentifier>test1</x:InstanceIdentifier>
                <x:Type>TestId</x:Type>
            </x:Scope>
            <x:Scope>
                <x:Identifier>Context</x:Identifier>
                <x:InstanceIdentifier>other1</x:InstanceIdentifier>
                <x:Type>OtherId</x:Type>
            </x:Scope>
        </x:Scopes>
        <x:Receiver>
            <x:Identifier>testreceiverid</x:Identifier>
        </x:Receiver>
        <x:DocumentIdentification>
            <x:Type>type1</x:Type>
            <x:Identifier>id1</x:Identifier>
            <x:TypeVersion>version1</x:TypeVersion>
        </x:DocumentIdentification>
    </x:TestHeader>
    <x:TestBody attribute1="attribute1" attribute2="attribute2">
        <TestingData>testingdata1</TestingData>
    </x:TestBody>
</x:TestDocument>
Pete
  • 41
  • 3
  • //x:Receiver/Identifier should be //x:Receiver/x:Identifier... – vtd-xml-author Sep 22 '17 at 18:37
  • Cheers that worked. One final question how can I get an XML Fragment in the standard version I could do the following long l = vtdNavStandard.getContentFragment(); System.out.println(vtdNavStandard.toString((int) l, (int) (l >> 32))); I notice that vtdNavHuge.getContentFragment() returns long[] and that toString(int, int) isn't available in the Huge version – Pete Sep 24 '17 at 17:17
  • it is not available, but may become available soon... – vtd-xml-author Sep 26 '17 at 01:40
  • Ok, that would be cool. Can you give me a shout when it's available? – Pete Sep 26 '17 at 08:41

1 Answers1

0

You are getting the exception because of a few issues: some with your code, others with extended VTD-xml.

First, you are not turning on the namespace awareness with the second code piece of VTD huge.

You are also not setting the namespace binding right..

  ap.declareXPathNameSpace("x", "http://test/namespaces/ssfgf");

Third, getText() returns a -1, which is causing the exception.

Finally, //test will not match any node... so getText() would certainly return -1.

vtd-xml-author
  • 3,319
  • 4
  • 22
  • 30