【发布时间】:2017-05-14 11:57:10
【问题描述】:
有点问题。我有以下代码:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse("result1.xml");
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
XPathExpression expr = xpath.compile("//element");
String elements = (String) expr.evaluate(doc, XPathConstants.STRING);
我得到了什么:
jcruz0@exblog.jp
Cheryl
Blake
195115
我想要什么:
<person>
<email>jcruz0@exblog.jp</email>
<firstname>Cheryl</firstname>
<lastname>Blake</lastname>
<number>195115</number>
</person>
如您所见,我想要完整的 XML 树。不仅仅是 NodeValue。 也许有人知道诀窍。 感谢您的帮助。
【问题讨论】: