c# - simple xpath not working to find a node -


iam trying particular node value equals input parameter,my xpath b node need

string xpath = "/batches/measurement/batch[market=someval]/b";  <?xml version="1.0" encoding="utf-8" ?> <batches>   <measurement>     <batch>       <market>someval</market>       <b>someval</b>     </batch>   </measurement> </batches>  var xmlnode = xmldoc.selectnodes(xpath); 

no nodes retruned count 0 ,i checked xmldoc loaded properly.

your xpath perfect. keep in mind const values have put in apostrophe:

"/batches/measurement/batch[market='someval']/b" 

update: c# code example:

 xmlnodelist nodelist;  nodelist = root.selectnodes("/batches/measurement/batch[market='someval']/b");   foreach (xmlnode node in nodelist)   {       (int = 0; < node.childnodes.count; i++)       {           console.writeline(node.childnodes[i].innertext);       }          } 

the return value of selectnodes nodelist. have iterate through it.

and little bit shorter:

      xmlelement root = doc.documentelement;       string text;       text = root.selectsinglenode("/batches/measurement/batch[market='someval']/b").innertext;       console.writeline(text); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -