I have small Strings with XML, like:
String myxml = "goodhi";
which I want to query to get their content.
What would be the simplest way to do this?
解决方案
XPath using Java 1.5 and above, without external dependencies:
String xml = "goodhi";
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
InputSource source = new InputSource(new StringReader(xml));
String status = xpath.evaluate("/resp/status", source);
System.out.println("satus=" + status);