Tôi đang viết một chương trình bằng Java có một tệp XML tùy chỉnh và phân tích nó. Tôi đang sử dụng tệp XML để lưu trữ. Tôi nhận được lỗi sau trong Eclipse.Tài liệu XML phân tích cú pháp Java cho "Nội dung không được phép trong prolog". lỗi
[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 )
Sự khởi đầu của tập tin XML được bao gồm: Chương trình
<?xml version="1.0" ?>
<PSU>
<Major id="IST">
<name>Information Science and Technology</name>
<degree>B.S.</degree>
<option> Information Systems: Design and Development Option</option>
<requirements>
<firstlevel type="General_Education" credits="45">
<component type="Writing_Speaking">GWS</component>
<component type="Quantification">GQ</component>
là khả năng đọc trong file XML nhưng khi tôi gọi DocumentBuilder.parse(XMLFile)
để có được một phân tích cú pháp org.w3c.dom.Document
, tôi nhận được lỗi trên.
Dường như tôi không có nội dung không hợp lệ trong phần mở đầu của tệp XML của tôi. Tôi không thể tìm ra điều gì sai. Hãy giúp tôi. Cảm ơn.
Tôi đã tìm thấy lỗi của mình. Tôi đã đọc trong thư mục tập tin đã ở trong và không phải là tập tin chính nó.Rõ ràng nếu bạn đọc trong một thư mục dưới dạng một tệp và gọi tệp File.exists() trên đó, nó sẽ vẫn trả về true. Stupid tôi ... Cảm ơn tất cả sự giúp đỡ. – ericso
kiểm tra câu trả lời của tôi tại http://stackoverflow.com/questions/3665554/about-saxparseexception-content-is-not-allowed-in-prolog/7023984 hoặc chỉ cần kiểm tra liên kết này http://mark.koli.ch/2009 /02/resolving-orgxmlsaxsaxparseexception-content-is-not-allowed-in-prolog.html – Starfish
không biết nếu nó sẽ giúp bất cứ ai nhưng tôi đã nhận lỗi này cố gắng sử dụng flavorDimensions và đặt drawable-xhdpi dưới res trong hương vị của tôi. Khi tôi đã thay đổi nó thành drawable .. tất cả cố định – dangalg