Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to parse xml having multiple child and in that child there is data?
    primarykey
    data
    text
    <ul> <li><p>Here is my xml,</p> <pre><code>&lt;root&gt; &lt;child&gt; &lt;Lunchmenu&gt; &lt;id&gt;2&lt;/id&gt; &lt;lunch_date&gt;2013-10-24&lt;/lunch_date&gt; &lt;break_name&gt;Lunch&lt;/break_name&gt; &lt;class_id/&gt; &lt;school_id&gt;1&lt;/school_id&gt; &lt;batch_id/&gt; &lt;/Lunchmenu&gt; &lt;Eatable&gt; &lt;id&gt;2&lt;/id&gt; &lt;eatable_name&gt;Apples&lt;/eatable_name&gt; &lt;/Eatable&gt; &lt;/child&gt; &lt;child&gt; &lt;Lunchmenu&gt; &lt;id&gt;2&lt;/id&gt; &lt;lunch_date&gt;2013-10-24&lt;/lunch_date&gt; &lt;break_name&gt;Lunch&lt;/break_name&gt; &lt;class_id/&gt; &lt;school_id&gt;1&lt;/school_id&gt; &lt;batch_id/&gt; &lt;/Lunchmenu&gt; &lt;Eatable&gt; &lt;id&gt;3&lt;/id&gt; &lt;eatable_name&gt;Orange&lt;/eatable_name&gt; &lt;/Eatable&gt; &lt;/child&gt; </code></pre> <p></p></li> <li><p>I need to know that, is there any way to parse above xml's child as there are again two separate tags like Lunchmenu and eatable.</p></li> <li>I am using sax parser to parse this xml.</li> <li>I know how to parse single child tag having data and again its iteration, but here I am confused how to do it?</li> <li>please suggest any solution if anyone knows How to parse it??</li> <li><p>thank you</p></li> <li><p>and my parser class is : SchoolParser.java</p></li> </ul> <p>public class SchoolParser extends DefaultHandler {</p> <pre><code>private List&lt;School&gt; schoolListData ; private boolean isSuccess; private School school; StringBuilder tempData; @Override public void startDocument() throws SAXException { super.startDocument(); Log.e("StudentListParser","startDocument"); schoolListData = new ArrayList&lt;School&gt;(); } public List&lt;School&gt; getSchoolListData(){ return schoolListData; } @Override public void startElement(String uri, String localName, String qName, org.xml.sax.Attributes attributes) throws SAXException { super.startElement(uri, localName, qName, attributes); if (localName.equals("School")) { school = new School(); Log.e("SchoolParser", "-----START----"); } tempData = new StringBuilder(); } @Override public void characters(char[] ch, int start, int length) throws SAXException { super.characters(ch, start, length); tempData.append(new String(ch, start, length)); } @Override public void endElement(String uri, String localName, String qName) throws SAXException { super.endElement(uri, localName, qName); if(localName.equals("School")){ schoolListData.add(school); Log.d("localName",localName); } else if (localName.equals("id")) { Log.e("id", localName); school.id = Integer.parseInt(tempData.toString()); } else if (localName.equals("school_name")) { school.schoolName = tempData.toString(); Log.e("name", localName); } else if (localName.equals("logo")) { school.logo = tempData.toString().getBytes(); Log.e("logo", localName); }else if (localName.equals("phone")) { school.phn_no = tempData.toString(); Log.e("phn no", localName); } else if (localName.equals("School")) { Log.e("SchoolParser", "----END---"); } // int size = buffer.length(); // buffer.delete(0, size); // Log.i("buffer is empty", ""+buffer.toString()); } @Override public void endDocument() throws SAXException { super.endDocument(); isSuccess = false; Log.e("StudentListParser", "endDocument"); } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload