Sorry to bother you with such a simple question, but I'm stuck here since an hour:
I have an xml file that looks something like this:
<?xml version="1.0" encoding="utf-8"?>
<aaa xmlns="http://blabla.com/xmlschema/v1">
<bbb>
<ccc>Foo</ccc>
</bbb>
<ddd x="y" />
<ddd x="xx" />
<ddd x="z" />
</aaa>
I'm trying to access the elements 'ddd' like this:
var doc = new XmlDocument();
doc.Load("example.xml");
foreach (XmlNode dddNode in doc.DocumentElement.SelectNodes("//ddd"))
{
// do something
Console.WriteLine(dddNode.Attributes["x"].Value);
}
At runtime the foreach loop is skipped because I don't get any nodes back from the .SelectNodes method. I breaked before the loop and had a look at the InnerXML, that looks fine, and I also tried all sorts of XPaths (like "//bbb" or "/aaa/ddd"), but only "/" seems to not return null.
This exact code worked for me before, now it does not. I suspect something with that namespace declaration in the aaa tag, but I couldn't figure out why this should cause problems. Or.. can you see anything I may be missing?