Sunday 14 May 2017

Java XML XPath Full XML

got a little problem. I have the following code:

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);

What i get :

        jcruz0@exblog.jp
        Cheryl
        Blake
        195115

What i want:

<person> 
  <email>jcruz0@exblog.jp</email>
  <firstname>Cheryl</firstname>
  <lastname>Blake</lastname>
  <number>195115</number> 
</person>

So as you can see i want the full XML tree. Not just the NodeValue. Maybe somebody knows the trick. Thanks for any help.



via K Christl

No comments:

Post a Comment