2011-01-20 271 views
3

試圖SAX解析在解析XML未綁定的前綴

<foo bar:car="zoo"/> 

結果:

org.dom4j.DocumentException: Error on line 1 of document file:///c:/temp/test.xml : The prefix "bar" for attribute "bar:car" associated with an element type "foo" is not bound. Nested exception: The prefix "bar" for attribute "bar:car" associated with an element type "foo" is not bound. 
     at org.dom4j.io.SAXReader.read(SAXReader.java:482) 
     at org.dom4j.io.SAXReader.read(SAXReader.java:321) 
     at .<init>(<console>:18) 
     at .<clinit>(<console>) 
     at RequestResult$.<init>(<console>:9) 
     at RequestResult$.<clinit>(<console>) 
     at RequestResult$scala_repl_result(<console>) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.ja... 

如何我可以解決,如果不改變XML? (真正的XML來自一個web服務我都無法控制)

回答

-1

禁用http://xml.org/sax/features/namespaces

xmlReader.setFeature("http://xml.org/sax/features/namespaces", false); 

這將防止命名空間前綴轉化成的URI。

+0

你能詳細說一下嗎? – IttayD 2011-01-20 06:17:43

相關問題