开发者

How to parse a String of xml in Java? [duplicate]

This question already has answers here: 开发者_开发百科 Closed 11 years ago.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜