जावा का एक्सएमएल पार्सर सोच रहा है कि मेरा एक्सएमएल दस्तावेज़ मूल तत्व के बाद अच्छी तरह से गठित नहीं है। लेकिन मैंने इसे कई टूल के साथ मान्य कर दिया है और वे सभी असहमत हैं। यह शायद दस्तावेज़ में बजाए मेरे कोड में एक त्रुटि है। मैं वास्तव में किसी भी मदद की सराहना करता हूं जो आप सभी मुझे दे सकते हैं।जावा कह रहा है कि एक्सएमएल दस्तावेज़ अच्छी तरह से तैयार नहीं है
<?xml version="1.0"?>
<tasklist>
<task>
<description>Task 1</description>
<due>Due date 1</due>
<comment>Comment 1</comment>
<completed>false</completed>
</task>
<task>
<description>Task 2</description>
<due>Due date 2</due>
<comment>Comment 2</comment>
<completed>false</completed>
</task>
<task>
<description>Task 3</description>
<due>Due date 3</due>
<comment>Comment 3</comment>
<completed>true</completed>
</task>
</tasklist>
है त्रुटि संदेश जावा मेरे लिए फेंक रहा है यहाँ और::
private void loadFromXMLFile(File f) throws ParserConfigurationException, IOException, SAXException {
File file = f;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db;
Document doc = null;
db = dbf.newDocumentBuilder();
doc = db.parse(file);
doc.getDocumentElement().normalize();
String desc = "";
String due = "";
String comment = "";
NodeList tasksList = doc.getElementsByTagName("task");
for (int i = 0; i tasksList.getLength(); i++) {
NodeList attributes = tasksList.item(i).getChildNodes();
for (int j = 0; i < attributes.getLength(); j++) {
Node attribute = attributes.item(i);
if (attribute.getNodeName() == "description") {
desc = attribute.getTextContent();
}
if (attribute.getNodeName() == "due") {
due = attribute.getTextContent();
}
if (attribute.getNodeName() == "comment") {
comment = attribute.getTextContent();
}
tasks.add(new Task(desc, due, comment));
}
desc = "";
due = "";
comment = "";
}
}
निम्नलिखित एक्सएमएल फ़ाइल मैं लोड करने के लिए कोशिश कर रहा हूँ है:
यहाँ मेरी जावा विधि है
run:
[Fatal Error] tasks.xml:28:3: The markup in the document following the root element must be well-formed.
May 17, 2010 6:07:02 PM todolist.TodoListGUI <init>
SEVERE: null
org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed.
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 todolist.TodoListGUI.loadFromXMLFile(TodoListGUI.java:199)
at todolist.TodoListGUI.<init>(TodoListGUI.java:42)
at todolist.Main.main(Main.java:25)
BUILD SUCCESSFUL (total time: 19 seconds)
संदर्भ TodoListGUI.java:199 लिए
01 हैdoc = db.parse(file);
यदि संदर्भ किसी के लिए सहायक है, तो मैं एक सरल सूची बनाने के लिए एक सरल जीयूआई एप्लीकेशन लिखने की कोशिश कर रहा हूं जो कार्यों को परिभाषित करने वाली XML फ़ाइलों को पढ़ और लिख सकता है।
<?xml version="1.0" encoding="UTF-8" ?>
आप एक नमूना XML दस्तावेज़ पोस्ट कर सकते हैं? आप उन्हें दृश्यमान बनाने के लिए संपादित कर सकते हैं - –
आपका एक्सएमएल टैग खाया किया गया है लगता है? आपको '' '' '<' 'के साथ '' 'प्राप्त करने में सक्षम होना चाहिए। – psmears
@psmears: नहीं, बस 4 रिक्त स्थान या कोड का चयन करें और फिर संपादक टूलबार में '010101' बटन दबाएं या' Ctrl + K' कुंजी दबाएं। – BalusC