Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to parse only the children where attribute = foo from xml using android.sax?
    primarykey
    data
    text
    <p>I have an some data stored in an xml file like so:</p> <pre><code>&lt;group name="example"&gt; &lt;article name="foo"&gt; &lt;content&gt;Lorem ipsum dolor sit amet.&lt;/content&gt; &lt;link&gt; &lt;title&gt;Lipsum&lt;/title&gt; &lt;url&gt;http://www.lipsum.com/feed/html&lt;/url&gt; &lt;/link&gt; &lt;/article&gt; &lt;article name="bar"&gt; &lt;content&gt;Lorem ipsum dolor sit amet.&lt;/content&gt; &lt;link&gt; &lt;title&gt;Google&lt;/title&gt; &lt;url&gt;http://www.google.com&lt;/url&gt; &lt;/link&gt; &lt;/article&gt; &lt;/group&gt; </code></pre> <p>Say I want to parse the specific article where <code>name="foo"</code> in android. I've been using the android.sax package so far, but I can't figure out if it even has this capability. Or if there's an alternative way to do this, I'd appreciate the help.</p> <p><strong>EDIT:</strong> This is the code I have so far. I feel like I'm missing something. The problem is it's adding information from ALL of the articles instead of just the specific one that I want. </p> <pre><code>public Article parse(final String articleTitle) { RootElement root = new RootElement("learning"); Element group = root.getChild("group"); final Element article = group.getChild("article"); article.setStartElementListener(new StartElementListener() { @Override public void start(Attributes attributes) { if (attributes.getValue("name").equals(articleTitle)) { currentArticle = new Article(); currentArticle.setTitle(articleTitle); setupArticle(currentArticle); } } private void setupArticle(final Article currentArticle) { article.getChild("content").setEndTextElementListener( new EndTextElementListener() { @Override public void end(String body) { currentArticle.setContent(body); } }); Context context = Application.getAppContext(); InputStream raw; try { raw = context.getAssets().open("learning_articles.xml"); Xml.parse(raw, Xml.Encoding.UTF_8, root.getContentHandler()); } catch (Exception e) { throw new RuntimeException(e); } return currentArticle; </code></pre>
    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