How to parse only the children where attribute = foo from xml using android.sax? -
I have a few data stored in an XML file like so:
& lt ; Group name = "example" & gt; & Lt; Article Name = "Foo" & gt; & Lt; Content & gt; Visit the website. & Lt; / Content & gt; & Lt; Link & gt; & Lt; Title & gt; Lipsum & lt; / Title & gt; & Lt; URL & gt; Http: //www.lipsum.com/feed/html< / URL & gt; & Lt; / Link & gt; & Lt; / Article & gt; & Lt; Article Name = "Bar" & gt; & Lt; Content & gt; Visit the website. & Lt; / Content & gt; & Lt; Link & gt; & Lt; Title & gt; Google & lt; / Title & gt; & Lt; URL & gt; Http: //www.google.com< / URL & gt; & Lt; / Link & gt; & Lt; / Article & gt; & Lt; / Groups & gt; Say I want to parse the specific article where name = "foo" is using the android.sax package in Android, but let me I do not know if this has the potential too. Or there is an alternative way to do this, if I would appreciate the help, Edit:. I have this code so far. I think that I am missing something, the problem is that I am only adding information to all articles instead of the specific one which I want. public parse parse (final string articleTitle) {RootElement root = new RootElement ("learning"); Element group = rootgetball ("group"); Final element article = group.getChild ("article"); Article.setStartElementListener {@Override Public Zero Start (Attributes Attributes) {If (attributes.getValue ("name"). Par (articleTitle)) {currentArticle = new article (); CurrentArticle.setTitle (articleTitle); SetupArticle (currentArticle);}} Private Zero setupArticle (last article currentArticle) {. Article.getChild ("content") setEndTextElementListener (New EndTextElementListener) {@Override Public Zero End (String Body) {currentArticle.setContent (body);}}); Reference Reference = Application.getAppContext (); InputStream Raw; Try {raw = context.getAssets (open) ("learning_articles.xml"); Xml.parse (raw, Xml.Encoding.UTF_8, root.getContentHandler ());} hold (exception e) {new runtime exception (e);} return currentArticle;
This is not an exact answer, but when I'm groove I do here Use something similar to that (which is capable of using sax):
-
I have personally installed it with Android Not that, but considering that Android, Java and Groove are equally similar in syntax, finding your answer from there should not be too difficult!
The way in which this example is both in Java and Groovy;) (Listing may be where you are interested)
Comments
Post a Comment