Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating and dealing with XmlNodeList

I have code like so:

string xml = "<root><span tag=\"LUMP\" missingValue=\"3,4,5,6,7,8\" format=\"Disc\" varName=\"RACE\" label=\"Race/ethnicity\"><element value=\"1+2\" label=\"Total 1+2\" /><element value=\"1\" label=\"White\" /><element value=\"2\" label=\"Black or African American\" /></span></root>";

 doc.LoadXml(xml);

 XmlNodeList varsList = doc.SelectNodes("span");

But everytime varsList is empty. Why?

like image 337
cdub Avatar asked Feb 18 '26 12:02

cdub


1 Answers

"span" XPath means "immediate child nodes with name span". Since immediate child is root you get nothing.

You want either "//span" (all spans anywhere in the tree starting from root) or "/root/span" ("root" at root, than its "span" children).

like image 146
Alexei Levenkov Avatar answered Feb 21 '26 03:02

Alexei Levenkov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!