Parsing a XML file in Android - android

Can anyone provide me with the info to parse an XML file in an Android application.
Any link on this will be helpful.

There are 3 different ways to parse XML in android: SAX parser, DOM parser, pull parser. Which one to use depends on how big your xml is, and what you want to do with it. See working with xml in Android for details. (Which, incidentally, is the 1st link if you google "Android XML"].

Parsing XML in android is done in more than one ways in android..
Android.developer is the best reference that you can go for.
you can ieither use SAX or DOM..
Here is the link which will give u idea about parsing XMl
http://developer.android.com/reference/javax/xml/parsers/package-summary.html
go through the documentation first it will help u a lot

You can find a great explanation at this link.
You basically use the dom4j SAXReader to parse the XML using XPath.

Related

Parse layout not from resources and set it in Runtime

I got a thing to think about, but cannot find the solution. New layout file is being received from the server.
I faced problem that Parser cannot resolve all those android attributes to inflate view in the next step. We can change file format on server-side to make it as attributes, but how to parse it and set properly still a question.
Does anybody have any idea or suggestions how to do that? Thanks in advance.
You can't. Two problems.
1)You can't parse a general xml file and make a layout from it. From the docs on LayoutInflater.inflate() "Important For performance reasons, view inflation relies heavily on pre-processing of XML files that is done at build time. Therefore, it is not currently possible to use LayoutInflater with an XmlPullParser over a plain XML file at runtime."
2)You can't save to assets. Assets are read only. Of course you could use the filesystem instead.
You can get what you want, but you'd have to write your own parser for your layout files from scratch. Its highly not recommended.

Storing data in pre-defined XML files

I'm trying to figure out how to store data in pre-defined xml files (the files should be part of the project).
I've tried to several methods but non worked.
Instead of asking what is wrong with what I'm doing, I rather ask what is a good known working method to do that.
Thanks.
There are plenty of tutorials about parsing xml. Try those by IBM. Just place your xml in/assets and parse it. But I believe newest api has even more convinient way to do it. Refer to dev guide. As fo xml itself just follow common standarts.
http://www.ibm.com/developerworks/opensource/library/x-android/

how to get html content from XML using SAX parser in android

i tried using CDATA in the xml i worked on most of the answers given in stackoverflow but i could not find the answer.
When CDATA is included, parser is not at all recognizing the data.
Is this any problem with android or are there any other parsers to parse? I tried using DOM, but since my xml file is too large DOM is unable to handle it. Please suggest me any working parser or a way to parse the html content.. Thank you..
I have had problems with CDATA in the xml, it happens for Android < 2.2 because it uses an ancient and buggy version of Xerces (I think it was Xerces that Android is using). Try to build your project for 2.2 and give it a try.
If you can't use 2.2 - there is a manual workaround that I was able to pull off. Unfortunately, I don't have the code for it in handy at the moment, sorry about that :(

3rd party Android XML parser?

Would you please tell me about any good third party xml parsing library that can be used in Android
thanks
Simple XML is just WONDERFUL. You can use SAX or DOM which come in the official SDK, but compared to SimpleXML they are too complex (again: compared to Simple XML).
You can use SAX or JDOM. I believe SAX is a bit faster than JDOM. You can find more information about SAX on Wikipedia: http://en.wikipedia.org/wiki/Simple_API_for_XML
Also, here's a link to SAX on Android and class references from android.com: http://developer.android.com/reference/android/sax/package-summary.html

Android: Best XML Parsing Library?

I have to parse some complex xml files inside my Android application. Is there any good library for doing that like there is TouchXMl for iPhone?
Or you could use the org.xmlpull.v1.XmlPullParser - I've found it much easier to use than the SAX Parser and it has other benefits:
http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html
http://www.bearcave.com/software/java/xml/xmlpull.html
The SAX XML Parser comes already built into the Android SDK.
Use Woodstox. It's a Stax pull parser, actually supports all of XML (unlike xmlpull that is bundled), efficient, mature. For more convenience, StaxMate helps too, uses Woodstox (or any other Stax parser) for parsing but exposes convenient cursors and writers; but is still 3x - 5x faster than DOM approach.
XmlPullParser that was mentioned works to some degree, but can't handle DTDs (not just validation but even basic character entities), gives cryptic error messages and doesn't have standard interface (SAX or Stax).
Don't know the criteria by which "best" is defined. but here is a recent research paper that analyzes existing java xml framework with great details...
http://recipp.ipp.pt/bitstream/10400.22/1847/1/ART_BrunoOliveira_2013.pdf

Categories

Resources