How To Get An XmlNode Value Using XPath Search



TODO:

Have you ever wanted to search a document for nodes with a certain name, and get their associated value?

 

SOLUTION:

 

string productCode = "";

//get a node list of all products with a venue id of 278652
XmlNodeList events = myDocument.DocumentElement.SelectNodes("product[VenueID='278652']");

//go through each node and get the product code
foreach (XmlNode eventNode in events)
{
     productCode = eventNode.SelectSingleNode("product_code").InnerText;   

     //do some other stuff here...
}

 

 

NOTES:

No notes on this topic.



Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading