sách gpt4 ăn đã đi

Java 解析 XML 文档给出 "Content not allowed in prolog."错误

In lại Tác giả: IT Lão Cao 更新时间:2023-10-28 20:32:49 26 4
mua khóa gpt4 giày nike

我正在用 Java 编写一个程序,它接受一个自定义 XML 文件并对其进行解析。我正在使用 XML 文件进行存储。我在 Eclipse 中收到以下错误。

[Fatal Error] :1:1: Content is not allowed in prolog.
org.xml.sax.SAXParseException: Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:239)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283 )
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208)
at me.ericso.psusoc.RequirementSatisfier.parseXML(RequirementSatisfier.java:61)
at me.ericso.psusoc.RequirementSatisfier.getCourses(RequirementSatisfier.java:35)
at me.ericso.psusoc.programs.RequirementSatisfierProgram.main(RequirementSatisfierProgram.java:23 )

包含 XML 文件的开头:




Information Science and Technology
B.S.



GWS
GQ

该程序能够读取 XML 文件,但是当我调用 DocumentBuilder.parse(XMLFile) 来获取已解析的 org.w3c.dom.Tài liệu 时,我得到上面的错误。

在我看来,我的 XML 文件的序言中没有无效内容。我不知道出了什么问题。请帮忙。谢谢。

câu trả lời hay nhất

请检查xml文件是否有这样的垃圾字符。如果存在,请使用以下语法删除。

String XString = writer.toString();
XString = XString.replaceAll("[^\\x20-\\x7e]", "");

关于Java 解析 XML 文档给出 "Content not allowed in prolog."错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2599919/

26 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress