title: How to read XML to a list of POJOs in Java?
body: <p>I'm new to XML and im trying to read in an XML page and store its contents in an arraylist.</p>
  
  <p>So far i seem to have been able to get the arraylist filled with the first content, as when i tried an isEmpty, it returned false. so there is definitely containing something.
  However, when i try to call the overided tostring method, or even try to call any individual category for that matter, it just returns empty?</p>
  
  <p>can anyone help?</p>
  
  <p>heres the code im working with:</p>
  
  <pre><code>package test;
  
  import java.io.File;
  import java.util.ArrayList;
  
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.parsers.DocumentBuilder;
  import org.w3c.dom.Document;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.Node;
  import org.w3c.dom.Element;
  
  public class xmlmx {
  
     public static void main(String[] args) {
        ArrayList&lt;Anime&gt; list = new ArrayList&lt;Anime&gt;();
        try {
           File inputFile = new File("c:\\code\\ad\\XMLDB.xml");
           DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
           DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
           Document doc = dBuilder.parse(inputFile);
           doc.getDocumentElement().normalize();
           System.out.println("Root element: " + doc.getDocumentElement().getNodeName());
           NodeList nList = doc.getElementsByTagName("Anime");
           System.out.println("----------------------------");
  
           for (int temp = 0; temp &lt; nList.getLength(); temp++) {
              Node nNode = nList.item(temp);
              System.out.println("\nCurrent Element :" + nNode.getNodeName());
  
              if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                 Element eElement = (Element) nNode;
                 list.add(new Anime(eElement.getAttribute("ID"),
                                    eElement.getAttribute("name"),
                                    eElement.getAttribute("altname"),
                                    eElement.getAttribute("seasons"),
                                    eElement.getAttribute("episodes"),
                                    eElement.getAttribute("status"),
                                    eElement.getAttribute("DS"),
                                    eElement.getAttribute("have"),
                                    eElement.getAttribute("left"),
                                    eElement.getAttribute("plot"),
                                    eElement.getAttribute("connect"),
                                    eElement.getAttribute("image")));
                 System.out.println(list.get(0).toString());
              }
           }
        } catch (Exception e) {
           e.printStackTrace();
        }
     }
  }
  </code></pre>
  
  <p>the arraylist is of type anime, a class here:</p>
  
  <pre><code>    package test;
  
  class Anime{
      private String ID;
      private String name;
      private String altname;
      private String seasons;
      private String episodes;
      private String status;
      private String DS;
      private String have;
      private String left;
      private String plot;
      private String connect;
      private String image;
  
      public Anime(String ID, 
                   String name,
                   String altname,
                   String seasons,
                   String episodes,
                   String status,
                   String DS,
                   String have,
                   String left,
                   String plot,
                   String connect,
                   String image) {
          this.ID = ID;
          this.name = name;
          this.altname = altname;
          this.seasons = seasons;
          this.episodes = episodes;
          this.status = status;
          this.DS = DS;
          this.have = have;
          this.left = left;
          this.plot = plot;
          this.connect = connect;
          this.image = image;
      }
  
  /*
   getters and setters here...
  */
      @Override
      public String toString() {
          return "Anime [ID=" + ID + 
                 ", name=" + name + 
                 ", altname=" + altname + 
                 ", seasons=" + seasons + 
                 ", episodes=" + episodes + 
                 ", status=" + status + 
                 ", DS=" + DS + 
                 ", have=" + have + 
                 ", left=" + left + 
                 ", plot=" + plot + 
                 ", connect=" + connect + 
                 ", image=" + image + "]";
      }
  }
  </code></pre>
  
  <p>finally, heres the xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Anime&gt;
      &lt;record ID="BL1"&gt;
          &lt;name&gt;Bleach&lt;/name&gt;
          &lt;altname&gt;Burichi&lt;/altname&gt;
          &lt;seasons&gt;16&lt;/seasons&gt;
          &lt;episodes&gt;366&lt;/episodes&gt;
          &lt;status&gt;Finished&lt;/status&gt;
          &lt;sound&gt;Dubbed&lt;/sound&gt;
          &lt;have&gt;All&lt;/have&gt;
          &lt;left&gt;-/-&lt;/left&gt;
          &lt;plot&gt;Ichigo gets grim reaper powers, fights reapers, hollows and everything in between&lt;/plot&gt;
          &lt;connect&gt;Bleach movies&lt;/connect&gt;
          &lt;image&gt;images/bleach.jpg&lt;/image&gt;
      &lt;/record&gt;
  &lt;/Anime&gt;
  </code></pre>
  
  <p>any help would be greatly appreciated, thank you</p>