1

xPath in SelectNodes method below does not return any node, even if there are such nodes in xCurrent document.

XmlDocument xCurrent = new XmlDocument();
xCurrent.Load(File);
foreach (XmlNode Node in xCurrent.DocumentElement.SelectNodes("//Product"))
{
    ...
}

My assumption that it should is based on this: https://msdn.microsoft.com/pl-pl/library/ms256086(v=vs.110).aspx

//author All <author> elements in the document.

However I've found that following xPath returns what is required

xCurrent.DocumentElement.SelectNodes("//*[local-name()=\"Product\"]"))

It seems for me that xPath assumes that "//Product" means "//elibri:Product", because "//" xPath returns only "elibri:Dialect" node. What is the reason behind that assumption? List of child nodes of DocumentElement is below.

List of child nodes from VS debugger

  • 1
    Please could you show us a short example of the document? My guess is that it's got a default namespace (`xmlns="..."`) at some point, but we're guessing until we see the doc. As an aside, LINQ to XML (XDocument etc) makes it really easy to work with namespaces. – Jon Skeet Oct 26 '18 at 13:27
  • 1
    @JonSkeet You mean that part do that: `` ? – Michał Woliński Oct 26 '18 at 13:31
  • 2
    Yes. Any child elements of that element will default to a namespace of `"http://ns.editeur.org/onix/3.0/reference"`. (That's not a .NET thing - it's just regular XML.) – Jon Skeet Oct 26 '18 at 13:48

0 Answers0