title: XML Parsing into list of objects
body: <p>I want to parse any XML file into a list of objects of "XMLNode" class using "SAXParser"</p>
  
  <p>XMLNode Class</p>
  
  <pre><code>public class XMLNode {
  
      private String nodeName;
      private String nodeValue;
      private List&lt;XMLNodeAttribute&gt; attributes;
      private boolean isParentNode;
      private List&lt;XMLNode&gt; childNodes;
  
      //.... getters and setters ....
  }
  </code></pre>
  
  <p>XMLNodeAttribute Class</p>
  
  <pre><code>public class XMLNodeAttribute {
  
      private String name;
      private String value;
  
      //.... getters and setters ....
  
  }
  </code></pre>
  
  <p>Please help me in writing the parser class which can take input as a XML file and output the List. </p>
  
  <p>Thank you in advance. </p>
  
  <p>I am able to write some code..</p>
  
  <pre><code>public class XmlProcesser extends DefaultHandler {
  
      XMLResponse xmlResponse = null;
      List&lt;XMLNode&gt; resplist  = new ArrayList();
      List&lt;XMLNode&gt; temp  = new ArrayList();
      boolean endtag = false;
  
      @Override
      public void startElement(String uri, String localName, String qName,
              Attributes attributes) throws SAXException {
  
           String elementName = localName;
              if ("".equals(elementName)) {
                  elementName = qName;
              }
          System.out.println(" Start Ele - " + elementName  );
  
          //Each attribute
  
          if (elementName!=null) {
              if (attributes!=null) {
                      for (int pos=0; pos&lt;attributes.getLength(); pos++) {
                          String name = attributes.getLocalName(pos)==null || attributes.getLocalName(pos).trim().length()==0 ? attributes.getQName(pos) : attributes.getLocalName(pos);
                          String value= attributes.getValue(pos);
                          System.out.println(" name - " + name  + "   value - "  + value  );
                      }
                  }
          }
  
      }
  
      @Override
      public void characters(char ch[], int start, int length) throws SAXException {
  
          String s = new String(ch, start, length);
          System.out.println(" value - " + s   );
  
          endtag = false;
      }
  
      @Override
      public void endElement(String uri, String localName,
              String qName) throws SAXException {
          endtag = true;
  
          String elementName = localName;
              if ("".equals(elementName)) {
                  elementName = qName;
              }
          System.out.println(" End Ele - " + elementName  );
  
      }
  }
  </code></pre>