0

I have an XML document that has nodes/values like this:

<data name="btnAutoTrans" xml:space="preserve">
  <value>Auto Trans</value>
</data>
<data name="btnDieEngine" xml:space="preserve">
 <value>Diesel Engine</value>
</data>

I need to select a single node for a specific name="btnDieEngine" (for example)

but all the code I have tried from searching google always returns NULL value.

The original code I had was

XmlNode node = xmldoc.SelectSingleNode("data[name='btnDieEngine']");

but this returns null.

Any help would be appreciated

MethodMan
  • 18,625
  • 6
  • 34
  • 52
Brad
  • 3,454
  • 3
  • 27
  • 50
  • have you tried something like this `Brad` `SelectSingleNode("//data[@name='btnDieEngine']").InnerText;` – MethodMan Apr 08 '13 at 16:25
  • Is there any reason that you aren't using [XDocument](http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx)? – Ryan Gates Apr 08 '13 at 16:39
  • No reason, I was just using xmldoc for all the other processing I was doing and it works fine that way. Can you provide an example of the xDocument? – Brad Apr 08 '13 at 18:05

1 Answers1

0

Your XPath is invalid. Try that one:

XmlNode node = xmldoc.SelectSingleNode("data[@name='btnDieEngine']");
MarcinJuraszek
  • 124,003
  • 15
  • 196
  • 263
  • That didnt work but if I used: xmldoc.SelectSingleNode("//data[@name='btnDieEngine']"); it kinda worked but gave me this: {element, Name="data"} vs the exact value I wanted and in VS it has drop down with a lot of values in it. If I search for all the data and I search for OuterXML it returns the value I need, but I am unsure how to get this value into a variable so that I can do something similar to node.RemoveAll() For that specific node name – Brad Apr 08 '13 at 18:21