java org.xml.sax.SAXParseException:元素的内容必须由格式正确的字符数据或标记组成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25072146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 07:16:56  来源:igfitidea点击:

org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup

javaxmlxml-parsing

提问by jhed

I'm doing it in Java XML Parser, then I got this error when parsing an xml file...

我在 Java XML Parser 中执行此操作,然后在解析 xml 文件时出现此错误...

[Fatal Error] jira.xml:192:64: The content of elements must consist of well-formed character data or markup. org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup. at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source) at javax.xml.parsers.DocumentBuilder.parse(Unknown Source) at com.icomteq.ReadXMLFile.main(ReadXMLFile.java:20)

[致命错误] jira.xml:192:64:元素的内容必须由格式正确的字符数据或标记组成。org.xml.sax.SAXParseException:元素的内容必须由格式正确的字符数据或标记组成。在 com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source) 在 com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source) 在 javax.xml.parsers .DocumentBuilder.parse(Unknown Source) at com.icomteq.ReadXMLFile.main(ReadXMLFile.java:20)

Any clue what could be the problem? Thank you.

任何线索可能是什么问题?谢谢你。

Here is the code used-> http://s29.postimg.org/tjbzvsn3b/xmlreader.jpg

这是使用的代码- > http://s29.postimg.org/tjbzvsn3b/xmlreader.jpg

Here is my jira.xml->

这是我的 jira.xml->

<?xml version="1.0" ?>
<DATA_RECORD>
<DESCRIPTION>
&lt;< inside &amp;& the description tag &lt;<
</DESCRIPTION>
</DATA_RECORD>

Temporary solution-> I figured out that XML Norms <should not be in the xml, so I will use contents.toString().replaceAll("&lt;<", "&lt;").replaceAll("&amp;&", "&amp;")

临时解决方案-> 我发现 XML 规范<不应该在 xml 中,所以我将使用contents.toString().replaceAll("&lt;<", "&lt;").replaceAll("&amp;&", "&amp;")

回答by dave

To me it looks like you have an encoding problem with this line.

对我来说,您似乎对这一行有编码问题。

&lt;< inside &amp;& the description tag &lt;<

should either be

应该是

&lt;&lt; inside &amp;&amp; the description tag &lt;&lt;

&lt;&lt; inside &amp;&amp; the description tag &lt;&lt;

or it should be

或者应该是

&lt; inside &amp; the description tag &lt;