title: How to Parse XML in android and store it in class
body: <pre><code>&lt;layout&gt;
  
  &lt;menu1&gt;
      &lt;title&gt;Oil Painting&lt;/title&gt;
      &lt;sectioncount&gt;5&lt;/sectioncount&gt;
      &lt;cost&gt;0&lt;/cost&gt;
      &lt;appcode&gt;0&lt;/appcode&gt;
      &lt;section1.1&gt;
          &lt;title&gt;Oil Painting basics&lt;/title&gt;
          &lt;subtitle&gt;9 minutes 57 secs*!How to do Oil Painting&lt;/subtitle&gt;
          &lt;video1.1&gt;&lt;/video1.1&gt;
          &lt;imgvideo&gt;Landscape19.jpg&lt;/imgvideo&gt;
          &lt;description&gt;video1.html&lt;/description&gt;
      &lt;/section1.1&gt;
      &lt;section1.2&gt;
          &lt;title&gt;Advacned Oil Painintg&lt;/title&gt;
          &lt;subtitle&gt;6 minutes 23 secs*!Advanced Oil Painting&lt;/subtitle&gt;
          &lt;video1.2&gt;&lt;/video1.2&gt;
          &lt;imgvideo&gt;Landscape19.jpg&lt;/imgvideo&gt;
          &lt;description&gt;video1.html&lt;/description&gt;
      &lt;/section1.2&gt;
      &lt;section1.3&gt;
          &lt;title&gt;Watercolors basic&lt;/title&gt;
          &lt;subtitle&gt;9 minutes 51 secs*!How to use watercolors&lt;/subtitle&gt;
          &lt;video1.3&gt;&lt;/video1.3&gt;
          &lt;imgvideo&gt;fifa.jpg&lt;/imgvideo&gt;
          &lt;description&gt;video1.html&lt;/description&gt;
      &lt;/section1.3&gt;
      &lt;section1.4&gt;
          &lt;title&gt;Watercolors Advanced&lt;/title&gt;
          &lt;subtitle&gt;3 minutes 46 secs*!Advacned training- Watercolors&lt;/subtitle&gt;
          &lt;video1.4&gt;&lt;/video1.4&gt;
          &lt;imgvideo&gt;fifa.jpg&lt;/imgvideo&gt;
          &lt;description&gt;video1.html&lt;/description&gt;
      &lt;/section1.4&gt;
      &lt;section1.5&gt;
          &lt;title&gt;Enamel Painting Basic&lt;/title&gt;
          &lt;subtitle&gt;1 minute 56 secs*!Advacned training- Watercolors&lt;/subtitle&gt;
          &lt;video1.5&gt;&lt;/video1.5&gt;
          &lt;imgvideo&gt;fifa.jpg&lt;/imgvideo&gt;
          &lt;description&gt;video1.html&lt;/description&gt;
      &lt;/section1.5&gt;     
  &lt;/menu1&gt;
  
  &lt;menu2&gt;
      &lt;title&gt;Graphite Pencil Sketching&lt;/title&gt;
      &lt;sectioncount&gt;4&lt;/sectioncount&gt;
      &lt;cost&gt;.99&lt;/cost&gt;
      &lt;appcode&gt;0&lt;/appcode&gt;
      &lt;section2.1&gt;
          &lt;title&gt;Basic Graphite Pencil Sketching&lt;/title&gt;
          &lt;subtitle&gt;5 minutes 29 secs*!What you need to know&lt;/subtitle&gt;
          &lt;video2.1&gt;&lt;/video2.1&gt;
          &lt;imgvideo&gt;fifa.jpg&lt;/imgvideo&gt;
          &lt;description&gt;video1.html&lt;/description&gt;
      &lt;/section2.1&gt;
      &lt;section2.2&gt;
          &lt;title&gt;Advanced Graphite Pencil Sketching&lt;/title&gt;
          &lt;subtitle&gt;3 minutes*!The proffessional way&lt;/subtitle&gt;
          &lt;video2.2&gt;&lt;/video2.2&gt;
          &lt;imgvideo&gt;fifa.jpg&lt;/imgvideo&gt;
          &lt;description&gt;video1.html&lt;/description&gt;
      &lt;/section2.2&gt;
      &lt;section2.3&gt;
          &lt;title&gt;Graphite Pencil Tools&lt;/title&gt;
          &lt;subtitle&gt;5 minutes*!what should you use&lt;/subtitle&gt;
          &lt;video2.3&gt;&lt;/video2.3&gt;
          &lt;imgvideo&gt;Landscape19.jpg&lt;/imgvideo&gt;
          &lt;description&gt;video1.html&lt;/description&gt;
      &lt;/section2.3&gt;
      &lt;section2.4&gt;
          &lt;title&gt;Do's and Don't of Graphite Pencil Sketching&lt;/title&gt;
          &lt;subtitle&gt;5 minutes*Cautions and precautions&lt;/subtitle&gt;
          &lt;video2.4&gt;&lt;/video2.4&gt;
          &lt;imgvideo&gt;Landscape19.jpg&lt;/imgvideo&gt;
          &lt;description&gt;video1.html&lt;/description&gt;
      &lt;/section2.4&gt;
  &lt;/menu2&gt;
  
  &lt;menu3&gt;
      &lt;title&gt;Pen Sketching&lt;/title&gt;
      &lt;sectioncount&gt;3&lt;/sectioncount&gt;
      &lt;cost&gt;0&lt;/cost&gt;
      &lt;section3.1&gt;
          &lt;title&gt;Basic Pen Sketching&lt;/title&gt;
          &lt;subtitle&gt;2 minutes*!what you need to know&lt;/subtitle&gt;
          &lt;video3.1&gt;&lt;/video3.1&gt;
          &lt;imgvideo&gt;fifa.jpg&lt;/imgvideo&gt;
          &lt;description&gt;video1.html&lt;/description&gt;
      &lt;/section3.1&gt;
      &lt;section3.2&gt;
          &lt;title&gt;Advanced Pen Sketching&lt;/title&gt;
          &lt;subtitle&gt;3 minutes*!proffessional approach&lt;/subtitle&gt;
          &lt;video3.2&gt;&lt;/video3.2&gt;
          &lt;imgvideo&gt;fifa.jpg&lt;/imgvideo&gt;
          &lt;description&gt;video1.html&lt;/description&gt;
      &lt;/section3.2&gt;
      &lt;section3.3&gt;
          &lt;title&gt;Pen Sketching Tools&lt;/title&gt;
          &lt;subtitle&gt;3 minutes*!which pens to use&lt;/subtitle&gt;
          &lt;video3.3&gt;&lt;/video3.3&gt;
          &lt;imgvideo&gt;fifa.jpg&lt;/imgvideo&gt;
          &lt;description&gt;video1.html&lt;/description&gt;
      &lt;/section3.3&gt;
  &lt;/menu3&gt;
  &lt;/layout&gt;
  </code></pre>
  
  <ol>
  <li>I want to parse this xml code</li>
  <li>I can get all the values but I am having problem how to store it in class and retrieve it and show it in listview.. I can get title , section code . but problem is how can I get child node of multiple section and store it in ArrayList.</li>
  <li>Please help me to parse this xml. I have code on which I'm working but its too messed up. but if anyone want to see that I can show that.</li>
  </ol>
  
  <p>-</p>
  
  <pre><code>public class twitterFeedHandler extends DefaultHandler
  
  StringBuilder sb = null;
  String ret = "";
  boolean bStore = false;
  int howMany = 0;
  Context context;
  String a;
  boolean config = false;
  boolean menu = false;
  Boolean section = false;
  
  String elementValue = null;
  Boolean elementOn = false;
  
  private final static String TAG_Layout = "layout";
  private final static String TAG_COnfig = "configuration";
  private final static String TAG_Menu = "menu";
  
  public static XMLGettersSetters data = null;
  public static XMLGettersSettersMenu datamenu = null;
  
  twitterFeedHandler() {
  }
  
  
  }
  
  @Override
  public void startDocument() throws SAXException {
  
  }
  
  @Override
  public void endDocument() throws SAXException {
  
  }
  
  @Override
  public void startElement(String namespaceURI, String localName,
          String qName, Attributes atts) throws SAXException {
  
  
      try {
  
  
  
  
  
          elementOn = true;
  
          if (localName.equals(TAG_Layout)) {
              data = new XMLGettersSetters();
              datamenu = new XMLGettersSettersMenu();
          }if (localName.equals(TAG_COnfig)) {
  
              config = true;
              Log.i("Config localName", "configuration start");
  
          } else if (localName.equals(TAG_Menu)) {
  
              Log.i("Menu localName", "menu1 start");
  
              if (localName.equals("section1")) {
                  if(localName.equals("stitle1"))
                  Log.i("Section localName", "section start");
                  section = true;
  
              }
  
              menu = true;
  
  
              Log.i("DATA --- &gt; Menu ", datamenu.getCompany().toString());
          }
  
      } catch (Exception ee) {
  
          Log.d("error in startElement", ee.getStackTrace().toString());
      }
  }
  
  @Override
  public void endElement(String namespaceURI, String localName, String qName)
          throws SAXException {
  
      if (localName.equals("configuration")) {
  
          Log.i("Config localName", "configuration end");
          bStore = false;
      } else if (localName.equals("menu")) {
          Log.i("Menu localName", "menu end");
  
          if (localName.equals("section1")) {
              Log.i("Section localName", "section end");
              section = false;
          }
          menu = false;
      }
       if(localName.equals("title"))
           datamenu.setTitle(elementValue);
       if(localName.equals("sectioncount"))
           datamenu.setCompany_SectionCount(elementValue);
       if(localName.equals("section1"))
           if(localName.equals("stitle1"))
               datamenu.setSection(elementValue);
  
       Log.i("Menu localName214213132132132"," " + datamenu.getCompany_SectionCount() + " size " + datamenu.getSection());
      elementOn = false;
  
      }
  
  
  @Override
  public void characters(char[] ch, int start, int length)
          throws SAXException {
  
      if (elementOn) {
          elementValue = new String(ch, start, length);
          Log.i("---------&gt;Name", section + " " );
  
          if (config &amp;&amp; menu == false)
              data.setCompany(elementValue);
          else 
              datamenu.setCompany(elementValue);
  
          elementOn = false;
      }
  
  }
  
  public class XMLGettersSetters {
      private ArrayList&lt;String&gt; company = new ArrayList&lt;String&gt;();
  
      public ArrayList&lt;String&gt; getCompany() {
          return company;
      }
  
      public void setCompany(String company) {
          this.company.add(company);
  
      }
  }
  
  public class XMLGettersSettersMenu {
      private ArrayList&lt;String&gt; company = new ArrayList&lt;String&gt;();
      private ArrayList&lt;String&gt; title = new ArrayList&lt;String&gt;();
      private ArrayList&lt;String&gt; section_count = new ArrayList&lt;String&gt;();
      private ArrayList&lt;String&gt; section = new ArrayList&lt;String&gt;();
  
  
      public ArrayList&lt;String&gt; getCompany() {
          return company;
      }
  
      public void setCompany(String company) {
          this.company.add(company);
  
      }
  
      public void setTitle(String company) {
          this.title.add(company);
  
      }
  
      public ArrayList&lt;String&gt; getTitle() {
          return title;
      }
  
      public void setCompany_SectionCount(String company) {
          this.section_count.add(company);
  
      }
  
      public ArrayList&lt;String&gt; getCompany_SectionCount() {
          return section_count;
      }
  
      public void setSection(String company) {
          this.section.add(company);
  
      }
  
      public ArrayList&lt;String&gt; getSection() {
          return section;
      }
  }
  }
  </code></pre>