2017-09-21 3 views
4

거대한 네임 스페이스로 실행하면 작은 테스트 파일이 생성됩니다. 네임 스페이스를 제거하면 두 코드 모두에 문제가있는 것입니까? VTD-XML 거대한 데이터 xPathExpression이 네임 스페이스와 작동하지 않습니다.

이이 샘플 XML 불행히도 실제 XML

를 표시 할 수 없습니다입니다 내가 NS

와 거대한 코드 및 표준 모두에 java.lang.IndexOutOfBoundsException을 얻을 쓸모없는 코드를

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(); 
    } 

을 제거하기 위해 변경

<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> 
+0

// x : 수신자/식별자는 //이어야합니다. x : 수신자/x : 식별자 ... –

+0

효과가있는 건지. 마지막으로 한 가지 질문 표준 버전에서 XML Fragment를 얻는 방법은 다음과 같습니다. long l = vtdNavStandard.getContentFragment(); System.out.println (vtdNavStandard.toString ((int) l, (int) (1 >> 32))); vtdNavHuge.getContentFragment()가 long []을 반환하고 toString (int, int)을 거대한 버전 – Pete

+0

에서 사용할 수 없다는 것을 알게되었습니다. 사용할 수 없지만 곧 사용할 수있게 될 것입니다 ... –

답변

0

몇 가지 문제로 인해 예외가 발생합니다. 일부는 코드로, 다른 일부는 확장 VTD-xml로되어 있습니다.

먼저 VTD의 두 번째 코드 조각으로 네임 스페이스 인식을 설정하지 않습니다.

또한) 제

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

gettext를 (.. 오른쪽 바인딩 스페이스 설정 예외를 일으키는 -1을 리턴하지 않는다.

마지막으로 // 테스트는 어떤 노드와도 일치하지 않으므로 getText()는 -1을 반환합니다.

+0

위 코드를 실행 가능하도록 변경했습니다. – Pete