Java XPath API - get string representing subtree
问题 My question is not about xpath syntax, it's related to the java API surrounding xpath. Consider the following xml: <wrapper> <metadata> <somefield>somevalue</somefield> <anotherfield>othervalue</anotherfield> </metadata> <data> <some> <unique> <xml> <structure>stuff</structure> </xml> </unique> </some> </data> </wrapper> I can easily get the metadata fields using xpath by using the following code: XPath xp = XPathFactory.newInstance().newXPath(); Node node = (Node) xp.evaluate("/wrapper