How to parse a String of xml in Java? [duplicate]
Possible Duplicate:
Best way to parse an XML String in Java?
I have a String value which is actually an xml data. I have to parse the String of xml data and get individual value from it. How can we do this?
There are lots of different XML APIs in Java - some built into the framework, some not.
One of the simpler ones to use is JDOM:
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new StringReader(text));
// Now examine the document, perhaps by XPath or by navigating
// programmatically, like this:
String fooContents = doc.getRootElement()
.getChild("foo")
.getText();
for example xstream. It is very simple
精彩评论