XmlDocument – SelectNodes

I have tried a fair few different ways without much look, I’m hoping someone will be able to help 🙂

XML:

<?xml version="1.0" encoding="UTF-8"?>
<ListOrdersResponse xmlns="https://services.com/Orders/2013-09-01">
   <ListOrdersResult>
      <Orders>
         <Order>
            <Id>1</Id>
         </Order>
         <Order>
            <Id>2</Id>
         </Order>
      </Orders>
   </ListOrdersResult>
</ListOrdersResponse>

Tried:

var o =xmlDocument.SelectNodes("/ListOrdersResponse/ListOrdersResult/Orders/Order");
var o = xmlDocument.SelectNodes("/ListOrdersResponse/ListOrdersResult/Orders");
var o = xmlDocument.SelectNodes("//Orders");
var o = xmlDocument.SelectNodes("//Order");
var o = xmlDocument.SelectNodes("//Orders/Order");

var root = xmlDocument.DocumentElement;
var nsmgr = new XmlNamespaceManager(xmlDocument.NameTable);
nsmgr.AddNamespace("bk", "https://services.com/Orders/2013-09-01");
var orders = root.SelectNodes("descendant::bk:Orders/Order", nsmgr);

var root = xmlDocument.DocumentElement;
var nsmgr = new XmlNamespaceManager(xmlDocument.NameTable);
nsmgr.AddNamespace("bk", "https://services.com/Orders/2013-09-01");
var orders = root.SelectNodes("descendant::bk:Orders", nsmgr);

It just returns 0 records. 🙁

What am I doing wrong?


Source: xml

Leave a Reply