java - Using getNodeValue() to get text and inline elements -


this question has answer here:

i trying understand great tutorial on xpath in java (http://viralpatel.net/blogs/java-xml-xpath-tutorial-parse-xml/). explanation getting strings of text elements superb. cannot find way text , inline elements. xml in tutorial added <b> inline element:

<employee emplid="3333" type="user">     <firstname>big <b>jim</b></firstname>     <lastname>moriarty</lastname>     <age>52</age>     <email>jim@sh.com</email> </employee> 

i use code tutorial:

        system.out.println("**2***********************");         expression = "/employees/employee/firstname";         system.out.println(expression);         nodelist nodelist = (nodelist) xpath.compile(expression).evaluate(xmldocument, xpathconstants.nodeset);         (int = 0; < nodelist.getlength(); i++) {             system.out.println(nodelist.item(i).getfirstchild().getnodevalue());         } 

and skips inline:

/employees/employee/firstname big  

i wish whole contents of <firstname>, including tag, this

/employees/employee/firstname big <b>jim</b> 

i happy supply more code if needed.

try nodelist.item(i).getfirstchild().gettextcontent()

it return node , child nodes string.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -