I'm playing around with XElement stuff, and I've come across a difficulty.
The XML document that I'm reading contains an xmlns declaration on the main
node...
<root xmlns="http://www.me.com">
<ANode>
<BNode>Hello</BNode>
<BNode>Goodbye</BNode>
</ANode>
</root>
I want to be able to query this document using XPath. I can successfully
do this with the following:
XmlDocument doc = new XmlDocument();
doc.LoadXml(s);
XmlNamespaceManager nsm = new XmlNamespaceManager(doc.NameTable);
nsm.AddNamespace("t", "http://www.me.com");
int n = doc.SelectNodes("/t:root/t:ANode/t:BNode", nsm).Count;
.... and I see that n = 2.
But when I try to convert this to XElement (and who knows I may be
WWWAAAYYY off here as I'm just starting to look at this):
XmlReader rdr = XmlReader.Create(new StringReader(s));
XElement x = XElement.Load(rdr);
XmlNamespaceManager nsm = new XmlNamespaceManager(rdr.NameTable);
nsm.AddNamespace("t", "http://www.me.com");
int n = x.XPathSelectElements("/t:root/t:ANode/t:BNode", nsm).Count();
.... I get n = 0.
What am I doing wrong?
-mdb