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
Post a Comment