I have an XML file which I have retrieved the data via a Document variable. I need to extract data for a class which contains several fields. What is the easiest way to retrieve the records from the Document variable ?
For Document objet use DOM parser.
For XML files use SAX parser.
Try to use a SAX parser for XML parsing, because it is more memory efficient.
Related
In an Android app I'm wirting, I have an HTML-like document in the resources. Unfortunately, I retrieve it in an XmlResourceParser object (using getResources().getXml(R.xml.texts), but I need to do significvant minipulation to it which I can only get in an org.w3c.dom.Document object. How can I convert it?
To clarify my question :-)
I want to have the best of both worlds.
The speed of having a compressed xml
file
The speed of the SAX parser (
over a XmlResourceParser that is
normally used with binary files )
Most important question is: Can this be done?
Closest i came to the solution is.
OR open a raw resource ( not binary
formatted )
OR parse a binary xml file with a XmlResourceParser
I hope someone can help me get a bit further in this situation.
Edit: link to reflect SAX-parser speed
SAX parser is not more efficient than XmlResourceParser for XML in raw resource. Just use XmlResourceParser.
You can place your xml file assets folder and you can use Sax parser
InputStream xmlFileStram = getAssets().open(filePath); // this gives the file in your asset folder
XmlHandler xmlHandler = new XmlHandler(activity);
SAXParserFactory.newInstance().newSAXParser().parse(xmlFileStram, xmlHandler);
i want to parse xml file having HTML tags and special characters,this is my xml file
while working with SAX parser HTML content in not going to parse and text skipped from Special characters on words
can any one suggest me how to do it or Any links for the sample code or explain how to do it
Can you create an XML object resource with key-value pairs (basically a hashmap) using an XML file analogous to arrays.xml? This would be an analogue of NSDictionary from Obj-C.
i.e.
<key>foo</key>
<value>bar</value>
I'd like for the value to be an array of strings, and I'd like to be able to copy and paste from XML files in my Obj-C projects.
Thanks.
A good alternative is to create JSON objects, and access these using GSON. If you already have a PList resource from an iPhone project, one way to convert to JSON is to create an object from the PList and write it to a JSON string file.
I am getting the value from a web server. I am getting the value as a string. Can anybody tell me how to convert the string to an xml file and where to store the xml file in android? And how do I access the file to parse the value, can anybody give an example?
Any help would be appreciated
Thanks in advance
In my understanding, Your meaning of "getting the value as string" is parse the content of InputStream. I think you don't have to parse the content and then convert the string to xml file, you can just use FileOuputStream to write the data in InputStream into file system.
You can use SAX or DOM to parse xml, they are both supported by android. See this post for more info.
Just pass the inputstream(response) from webserver to the Dom or Sax Methods no need to convert in to String