解析带有未绑定前缀的 xml
尝试 SAX 解析
<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服务)
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)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
禁用
http://xml.org/sax/features/namespaces
:这将阻止将命名空间前缀转换为 URI。
Disable
http://xml.org/sax/features/namespaces
:This will prevent the conversion of namespace prefixes into URIs.