Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting "null" in place of textvalue After parsing XML using PullParser in Android
    primarykey
    data
    text
    <p>I had a look at <a href="http://developer.android.com/training/basics/network-ops/xml.html" rel="nofollow noreferrer">this</a>. SO please dont redirect me to that site.</p> <p>I had already used DOM parser and <a href="https://stackoverflow.com/questions/17421506/how-to-parse-same-name-tag-in-android-xml-dom-parsing">here</a> is my problem with that.</p> <p>I am having the same XML :</p> <pre><code>&lt;MyResource&gt; &lt;Item&gt;First&lt;/Item&gt; &lt;Item&gt;Second&lt;/Item&gt; &lt;/MyResource&gt; </code></pre> <p>And now i have no way but to parse this XML via PullParser. My methods as taken from <a href="http://developer.android.com/training/basics/network-ops/xml.html" rel="nofollow noreferrer">this</a>:</p> <pre><code>private List readFeed(XmlPullParser parser) throws XmlPullParserException, IOException { // TODO Auto-generated method stub List entries = new ArrayList(); parser.require(XmlPullParser.START_TAG, ns, "MyResource"); while (parser.next() != XmlPullParser.END_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) { continue; } String name = parser.getName(); // Starts by looking for the entry tag if (name.equals("MyResource")) { entries.add(readEntry(parser)); } else { skip(parser); } } return entries; } private void skip(XmlPullParser parser) throws XmlPullParserException, IOException { // TODO Auto-generated method stub if (parser.getEventType() != XmlPullParser.START_TAG) { throw new IllegalStateException(); } int depth = 1; while (depth != 0) { switch (parser.next()) { case XmlPullParser.END_TAG: depth--; break; case XmlPullParser.START_TAG: depth++; break; } } } private Item readEntry(XmlPullParser parser) throws XmlPullParserException, IOException { // TODO Auto-generated method stub parser.require(XmlPullParser.START_TAG, ns, "Item"); String text = null; while (parser.next() != XmlPullParser.END_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) { continue; } String name = parser.getName(); if (name.equals("Item")) { text = readMyText(parser); } else { skip(parser); } } return new Item(text); } private String readMyText(XmlPullParser parser) throws XmlPullParserException, IOException { // TODO Auto-generated method stub parser.require(XmlPullParser.START_TAG, ns, "Item"); String text = readText(parser); parser.require(XmlPullParser.END_TAG, ns, "Item"); return text; } private String readText(XmlPullParser parser) throws XmlPullParserException, IOException { String result = ""; if (parser.next() == XmlPullParser.TEXT) { result = parser.getText(); parser.nextTag(); } return result; } </code></pre> <p>I am getting this as the parsed text :</p> <pre><code>null null </code></pre> <p>Can anyone help me out of this ??</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.
 

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