【发布时间】:2015-03-06 19:54:35
【问题描述】:
我正在尝试将使用 Xpath 解析 XML 的 java 方法转换为使用 JsonPath 的方法,但我无法转换 Xpath 解析器正在执行的操作,因此我可以使用 JsonPath 复制它。
这是当前解析“String body”的代码。
public static String parseXMLBody(String body, String searchToken) {
String xPathExpression;
try {
// we use xPath to parse the XML formatted response body
xPathExpression = String.format("//*[1]/*[local-name()='%s']", searchToken);
XPath xPath = XPathFactory.newInstance().newXPath();
return (xPath.evaluate(xPathExpression, new InputSource(new StringReader(body))));
} catch (Exception e) {
throw new RuntimeException(e); // simple exception handling, please review it
}
}
任何人都可以帮助将其转换为使用 JsonPath 或类似方法的方法吗?
谢谢
【问题讨论】:
-
这有帮助吗? code.google.com/p/json-path
标签: java xml json parsing jsonpath