1

From this html

<text>
  <line1><bold>Hello</bold> world</line1>
  <line2>good bye</line2>
</text>

I want to get text along with tag inside as string. How can I do that? I try to use below xpath code but I couldn't get the tag.

XPathExpression expr = xPath.compile("/text/line1");
String result = expr.evaluate(doc, XPathConstants.STRING);
// This resulted in "Hello world"
// but I want "<bold>Hello</bold> world"

How could I get text inside including tag as string? Any suggestion would be appreciated.

0 Answers0