XML analysts of Java are thinking that my XML document is not well after the original element. But I have validated it with several tools and they all disagree. This is probably an error in the document, in my document. I would really appreciate any help you could give me,
Here is my Java method:.
private void loadFromXMLFile (File f) throws ParserConfigurationException, IOException, SAXException {file = f; DocumentBuilderFactory DBF = DocumentBuilderFactory.newInstance (); DocumentBuilder DB; Document doctor = null; Db = dbf.newDocumentBuilder (); Doc = db.parse (file); Doc.getDocumentElement () Normal () .; String del = ""; String payable = ""; String comment = ""; Node list agenda = doc.getElementsByTagName ("work"); (Int i = 0; i tasksList.getLength (); i ++) {node list attributes = actions list .it (i) .getChildNodes (); (Int j = 0; i & lt; attributes.getLength (); j ++) {node attribute = attributes.itim (i); If (attribute.getNodeName () == "description") {desc = attribute.getTextContent (); } If (attribute.getNodeName () == "cause") {cause = attribute.getTextContent (); } If (attribute.getNodeName () == "comment") {comment = attribute.getTextContent (); } Tasks.add (new job (desc, reason, comment)); } Desc = ""; Cause = ""; Comment = ""; }}
The following is the XML file I am trying to load:
& lt ;? XML version = "1.0"? & Gt; & Lt; Agenda & gt; & Lt; Work & gt; & Lt; Details & gt; Work 1 & lt; / Description & gt; & Lt; Reason & gt; Due date 1 & lt; / Cause & gt; & Lt; Comment & gt; Comment 1 & lt; / Comment & gt; & Lt; Complete & gt; False & lt; / Complete & gt; & Lt; / Work & gt; & Lt; Work & gt; & Lt; Details & gt; Work 2 & lt; / Description & gt; & Lt; Reason & gt; Due date 2 & lt; / Cause & gt; & Lt; Comment & gt; Comment 2 & lt; / Comment & gt; & Lt; Complete & gt; False & lt; / Complete & gt; & Lt; / Work & gt; & Lt; Work & gt; & Lt; Details & gt; Work 3 & lt; / Description & gt; & Lt; Reason & gt; Due date 3 & lt; / Cause & gt; & Lt; Comment & gt; Comment 3 & lt; / Comment & gt; & Lt; Complete & gt; True & lt; / Complete & gt; & Lt; / Work & gt; & Lt; / To do list & gt;
And the error message Java is thrown to me:
run [Fatal Error] tasks.xml: 28: 3: Markup origin The document should be prepared well after the element May 17, 2010 6:07:02 Prime Minister todolist.TodoListGUI & lt; Init & gt; SEVERE: null org.xml.sax.SAXParseException: After the root element, the markup in the document should be well formed. On com.sun.org.apache.xerces.internal.parsers.DOMParser.parse com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse (DOMParser.java:239) (DocumentBuilderImpl.java:283) . Init & gt; (TodoListGUI.java:42) todolist.Main on javax.xml.parsers.DocumentBuilder.parse (DocumentBuilder.java:208) todolist.TodoListGUI.loadFromXMLFile (TodoListGUI.java:199) key (on the todolist.TodoListGUI & lt Main.java:25) successful (Total time: build 19 seconds)
reference If reference is useful to anyone here, then I am trying to write a simple GUI application which can be written and written to manage the work list. p> Dock = database. Parse (file);
org.xml.sax.SAXParseException: Fundamentals should be well markup in the document - influenced.
This special exception indicates that there is more than one root element in the XML document. In other words, & lt; Agenda & gt;
is not the only core element to take your XML document as an example, & lt; Agenda & gt;
without the element and in the root three & lt; Work & gt;
Think without thinking the elements can be an exception to this type.
Since you have correctly observed the XML file you posted, the problem is elsewhere. It looks like this does not parse the XML file which you expect it to be parsing. For quick debugging, add the following to the top of your method:
System.out.println (f.getAbsolutePath ());
Find and verify the file in the disk file system.