开发者

Parsing xml with unbound prefixes

Trying to SAX parse

<foo bar:car="zoo"/>

Results in:

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)
开发者_JAVA技巧        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...

How can I work around that without changing the XML? (The real XML comes from a web service I have no control over)


Disable http://xml.org/sax/features/namespaces:

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

This will prevent the conversion of namespace prefixes into URIs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜