C# Xpath can't get element by name
See the question and my original answer on StackOverflowdoc.SelectSingleNode("//body");
doesn't work because body
is declared in a specific namespace "http://www.gribuser.ru/xml/fictionbook/2.0", so to query for it you could code it like this:
var mgr = new XmlNamespaceManager(new NameTable());
mgr.AddNamespace("whatever", "http://www.gribuser.ru/xml/fictionbook/2.0");
var node = doc.SelectSingleNode("//whatever:body", mgr);
doc.LastChild["body"]
; works because the implementation supports it, but you could use it like this to avoid ambiguities:
doc.LastChild["body", "http://www.gribuser.ru/xml/fictionbook/2.0"]