Results in: org.dom4j.DocumentException: Error on line 1 of...">

Xml parsing with unbound prefixes

Trying to analyze SAX

<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)
        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 get around this without changing the XML? (Real XML comes from a web service that I do not control)

+3
source share
1 answer

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

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

This will prevent the conversion of namespace prefixes to URIs.

-1
source

Source: https://habr.com/ru/post/1786580/


All Articles