title: Java saying XML Document Not Well Formed
body: <p>Java's XML parser seems to be thinking that my XML document is not well formed following the root element. But I've validated it with several tools and they all disagree. It's probably an error in my code rather than in the document itself. I'd really appreciate any help you all could offer me.</p>
  
  <p>Here is my Java method:</p>
  
  <pre><code>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 &lt; 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 = "";
      }
  }
  </code></pre>
  
  <p>The following is the XML file I'm trying to load:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;  
  &lt;tasklist&gt;  
      &lt;task&gt;  
          &lt;description&gt;Task 1&lt;/description&gt;  
          &lt;due&gt;Due date 1&lt;/due&gt;  
          &lt;comment&gt;Comment 1&lt;/comment&gt;  
          &lt;completed&gt;false&lt;/completed&gt;  
      &lt;/task&gt;  
      &lt;task&gt;  
          &lt;description&gt;Task 2&lt;/description&gt;  
          &lt;due&gt;Due date 2&lt;/due&gt;  
          &lt;comment&gt;Comment 2&lt;/comment&gt;  
          &lt;completed&gt;false&lt;/completed&gt;  
      &lt;/task&gt;  
      &lt;task&gt;  
          &lt;description&gt;Task 3&lt;/description&gt;  
          &lt;due&gt;Due date 3&lt;/due&gt;  
          &lt;comment&gt;Comment 3&lt;/comment&gt;  
          &lt;completed&gt;true&lt;/completed&gt;  
      &lt;/task&gt;  
  &lt;/tasklist&gt;
  </code></pre>
  
  <p>And here is the error message java is throwing for me:</p>
  
  <pre><code>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 &lt;init&gt;
  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.&lt;init&gt;(TodoListGUI.java:42)
          at todolist.Main.main(Main.java:25)
  BUILD SUCCESSFUL (total time: 19 seconds)
  </code></pre>
  
  <p>For reference TodoListGUI.java:199 is</p>
  
  <pre><code>doc = db.parse(file);
  </code></pre>
  
  <p>If context is helpful to anyone here, I'm trying to write a simple GUI application to manage a todo list that can read and write to and from XML files defining the tasks.</p>