xml - XPath search by "id" attribute , giving NPE - Java -


all,

i have multiple xml templates need fill data, allow document builder class use multiple templates , insert data correctly

i designate node want class insert data adding attribute of:

id="root"

one example of xml

<?xml version="1.0" encoding="utf-8" standalone="yes" ?> <siebelmessage messageid="07f33fa0-2045-46fd-b88b-5634a3de9a0b" messagetype="integration object" intobjectname="" intobjectformat="siebel hierarchical" returncode="0" errormessage="">     <listofreadaudit >         <readaudit id="root">             <recordid mapping="record id"></recordid>             <userid mapping="user id"></userid>             <customerid mapping="customer id"></customerid>             <lastupd mapping="last updated"></lastupd>             <lastupdby mapping="last updated by"></lastupdby>             <buscomp mapping="entity name"></buscomp>         </readaudit>     </listofreadaudit> </siebelmessage> 

code

expr = xpath.compile("//siebelmessage[@id='root']"); root = (element) expr.evaluate(xmldoc, xpathconstants.node); element temp = (element) root.clonenode(true); 

using example: xpath select element attribute value

the expression not working:

//siebelmessage[@id='root']

any ideas doing wrong?

try this:

//readaudit[@id='root'] 

this selects readaudit elements id attribute set root (it should 1 element in case).

you make sure returns maximum 1 element this:

//readaudit[@id='root'][1] 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -