1

I am trying to find a node in my xml file but getting the error ( see title)?

 // instantiate XmlDocument and load XML from file
        XmlDocument doc = new XmlDocument();
        doc.Load(@"C:\temp\test2.xml");
        var  node = doc.SelectSingleNode("/Offers/Offer/ID=[text()='1']");
        var test = node;

xml

<?xml version="1.0" encoding="utf-8"?>
<Offers>
  <Offer>
    <Model>AAAA</Model>
    <ID>1</ID>
    <Name>First offer</Name>
  </Offer>
  <Offer>
    <Model>BBBB</Model>
    <ID>2</ID>
    <Name>Second offer</Name>
  </Offer>
  </Offers>
user603007
  • 11,416
  • 39
  • 104
  • 168
  • It's a pretty poor error message because your XPath expression is syntactically invalid, it should be a syntax error not a type error. – Michael Kay Jun 28 '13 at 08:22

1 Answers1

3

Remove the = after ID:

 var  node = doc.SelectSingleNode("/Offers/Offer/ID=[text()='1']");

becomes:

 var  node = doc.SelectSingleNode("/Offers/Offer/ID[text()='1']");
Gauthier Boaglio
  • 10,054
  • 5
  • 48
  • 85