java - How to ignore tags while reading text from XML? -
i have xml text containing nested tags. construction complicated. have used xpath
queries access kid node described in answer. however, have encountered text within node contains xml tag. method stops reading encounters xml tag.
following xml file:
<x> <y> <z> <tag>text</tag> </z> </y> </x>
in above xml, text within <z>
can accessed next method:
xpath xpath = xpathfactory.newinstance().newxpath(); xpathexpression expr= xpath.compile("/x/y/z/text()"); string text = (string) expr.evaluate(doc, xpathconstants.string);
but value of text comes out "this a" only. want whole text displayed : this text
simply utilize xpathexpression expr= xpath.compile("/x/y/z");
.
java xml xpath
No comments:
Post a Comment