4
當我的命名空間運行失敗時,我有一個小的測試文件。如果我刪除命名空間這兩個工作我做錯了巨大的代碼?VTD-XML巨大的數據xPathExpression不能與名稱空間一起工作
更改刪除行不通代碼
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>
// x:接收者/標識符應該是// x:接收者/ x:標識符... –
工作的乾杯。最後一個問題我怎樣才能在標準版本中獲得一個XML片段?我可以做如下操作: long l = vtdNavStandard.getContentFragment(); System.out.println(vtdNavStandard.toString((int)l,(int)(l >> 32))); 我注意到,vtdNavHuge.getContentFragment()返回long [],並且該toString(int,int)在巨大版本 – Pete
中不可用,但可能會很快出現... –