I am trying to convert data from database to XML in android. After that i am planning to post xml data to server using HttpPost?. But i am not sure how to convert string to xml in android.
I am looking for any sample code and methods.
Thanks in advance
Use the DOM from java library.
Refer:
http://developer.android.com/reference/javax/xml/parsers/DocumentBuilder.html#parse(java.lang.String)
http://exampledepot.com/egs/javax.xml.parsers/BasicDom.html
Related
I'm sitting there for quite a while now, trying to process my xml file (similar to the one below). I want to check all tags, if is equal to a variable, and if so, then running readEntry() on the tag.
I followed this example: https://developer.android.com/training/basics/network-ops/xml.html
I also found this Article(Difficulty with XML nested tags with XMLPullParser in Android deals with this topic.
I have already tried a few things but get either nothing or XmlPullParserException.
A Example of my XML:
<VpMobil>
<Kopf>
...
</Kopf>
<FreieTage>
...
</FreieTage>
<Klassen>
<Kl>
<Kurz>5</Kurz>
<Pl>
<Std>
<St>1</St>
<Fa>Fa1</Fa>
<Le>NAME</Le>
<Ra>1009</Ra>
<Nr>131</Nr>
<If/>
</Std>
<Std>
<St>2</St>
<Fa>Fa2</Fa>
<Le>NAME</Le>
<Ra>1004</Ra>
<Nr>132</Nr>
<If/>
</Std>
</Pl>
</Kl>
<Kl>
<Kurz>6</Kurz>
<Pl>
<Std>
<St>1</St>
<Fa>Fa2</Fa>
<Le>NAME</Le>
<Ra>1046</Ra>
<Nr>131</Nr>
<If/>
</Std>
<Std>
<St>2</St>
<Fa>Fa3</Fa>
<Le>NAME</Le>
<Ra>1012</Ra>
<Nr>132</Nr>
<If/>
</Std>
</Pl>
</Kl>
</Klassen>
</VpMobil>
I would be very grateful if someone could explain to me how I can achieve this. Thanks in advance
You can use Jackson library to parse XML, it is as easy as parsing Json File. this tuto will help you to figure out.
However, bescause it is is a nested xml, you will need some nested POJOs to achieve parsing.
After a few more unsuccessful attempts, I got the idea to convert the XML into a JSON (Convert XML to JSON object in Android) and continue working with it. That worked then.
I'm building an RSS reader APP, and I've been told to use the XMLPullParser interface.
Here is the block of code I'm working with:
XmlResourceParser parser = context.getResources().getXml(resource);
'Resource' is a an integer with the R.id. integer of the Xml file. This is not an internal XML file, so I don't know how to work around this.
Any ideas? Is the XmlResourceParser the wrong approach for this project? I've seen XMLReaders used with content handlers as well. Can you integrate these technologies together?
Thank you
what is the type of your xml source?
xmlPullParser can be used to parse any xml sources.
It is in my opinion the way to do this. Only problem you may encounter is when the rss feed has empty lines. The xml pullparser of android (api-level 14) jumps to the /channel if this is the case. When implementing the parser try to use the AsyncTask to start the reading of the rss feed.
Success with the implementation.
I have list of records in xml format from my local host "http:localhost:810/Service1.svc/leb/GetAllCustomers"
Can I call this to android and list it in Textview or Spinner or in EditTextView or in any of the controls in android?
You should parse this xml file using SAX parse or Dom Parse in android and collect date in arrays/list/map according to your requirement here i am post some link to you get more information form there and get your ASAP.
http://www.androidpeople.com/android-xml-parsing-tutorial-using-saxparser
http://www.androidpeople.com/android-xml-parsing-tutorial-%E2%80%93-using-domparser
I hope this is very helpful to you.
Some links here for you.
1) Multithreading for Performance
to help you understand, how to download a file (example shows downloading an image) via AsyncTask.
2) Working with XML in Android
to help you parse your xml. Check these out. Good luck!
Yes you can do that.
Use Intent which takes URL as an argument.
In the URL you can mention the location/URI of your source.
Then, you can parse it to a string and store it.
Later, use ArrayAdapter to populate.
I can get you code if this is what you are trying to do.
I have an XML Document I want to create a method that will parse the XML which is in Document format to String and return the Strings . How can I do this..Please help me out as I am very new to Android and XML as well.Thanks in advance.
I am trying to do something like this----
public static String getStringFromXML(Document doc){
String data;
................
................
................
...............
return data;
}
Look at this article there are several examples on howto use SAX, DOM and PULL parsers
Working with XML on Android
You should use the given blow link and get idea how to parse xml in android then make function according to your requirement.
http://www.androidpeople.com/android-xml-parsing-tutorial-using-saxparser
[This is the another like is usfull to you for finding solution of your problem]
http://www.androidpeople.com/android-xml-parsing-tutorial-%E2%80%93-using-domparser
In android app, i want to send a php requeset, and am expecting a response in the form of xml, from the server.
Can anybody provide pointers in this case.
You can use XmlPullParser bundled with android to parse the response. To get the parser instance use this snippet:
XmlPullParser pullParser = XmlPullParserFactory.newInstance().newPullParser();
pullParser.setInput(...); //Set input source with response you parsing.
There are 3 methods for parsing XMl in android. See working with xml in android.
You may want to try out my XmlParsing library.
https://github.com/frenchie4111/XmlParser
Let me know if you have any problems with it.
Xstream is your friend http://x-stream.github.io/
XStream is a simple library to serialize objects to XML and back again.