Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java VTD-XML大数据xPathExpression不使用名称空间_Java_Vtd Xml - Fatal编程技术网

Java VTD-XML大数据xPathExpression不使用名称空间

Java VTD-XML大数据xPathExpression不使用名称空间,java,vtd-xml,Java,Vtd Xml,我有一个小的测试文件,在运行时命名空间巨大失败。如果我删除了名称空间,这两项工作都会起作用,那么我对庞大的代码做了什么错事吗 更改为删除不可行的代码 try { //without namespace works VTDGen vtdGen = new VTDGen(); vtdGen.parseFile("test.xml", false); VTDNav vtdNav = vtdGen.getNav();

我有一个小的测试文件,在运行时命名空间巨大失败。如果我删除了名称空间,这两项工作都会起作用,那么我对庞大的代码做了什么错事吗

更改为删除不可行的代码

    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();
    }
我获得了java.lang.IndexOutOfBoundsException,用于大型代码和NS标准

很遗憾,这是一个示例XML,它不能显示真正的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>

上下文
酪蛋白
案例1
商务助理1
上下文
测试1
睾丸
上下文
其他1
其他人
睾丸受器
类型1
id1
版本1
测试数据1

由于一些问题,您会遇到异常:一些问题与您的代码有关,另一些问题与扩展VTD xml有关

首先,在VTD的第二段代码中没有启用名称空间感知

您也没有设置名称空间绑定权限

  ap.declareXPathNameSpace("x", "http://test/namespaces/ssfgf");
第三,getText()返回导致异常的-1


最后,//测试将不匹配任何节点。。。所以getText()肯定会返回-1。

//x:Receiver/Identifier应该是//x:Receiver/x:Identifier……干杯,这很有效。最后一个问题是如何在标准版本中获取XML片段我可以执行以下长l=vtdNavStandard.getContentFragment();System.out.println(vtdNavStandard.toString((int)l,(int)(l>>32));我注意到vtdnavmaging.getContentFragment()返回long[],而toString(int,int)在庞大的版本中不可用。它不可用,但可能很快就会可用……好吧,那太酷了。有空的时候你能叫我一声吗?