Reputation: 48871
I have a requirement to both parse existing XML strings (retrieved from a database) and create new ones to store in the database.
I don't need full document parsing (I know haw to do that) - I just need to parse what would amount to a single document element of the form...
<rootElement><childElement1>value</childElement1><childElement2>value</childElement2>...</rootElement>
It's a single string saved as a db TEXT field and each child is unique (no repetitions).
For parsing (in pseudo-code) I'm looking for something like...
String xmlString = "<rootElement><helloElement>Hello</helloElement></rootElement>";
SomeParserClass xmlStringParser = new SomeParserClass("rootElement"); //Set root
String helloString = xmlStringParser.getValue("helloElement");
I'd also need something similar to create strings.
In C# I can use XmlTextReader and XmlTextWriter to perform similar things - is there a Java equivalent for Android?
Upvotes: 0
Views: 124
Reputation: 370
If you are processing a single element only, use XPath would be very convenient. If you want to read or write more than one element or even the whole XML file, try use DOM to do it. Both of them are included in Standard Java API.
Upvotes: 1