I’m querying the gmail feed using XmlReader and XDocument and I’m running in to trouble with namespaces being automatically appended to all elements.
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = new NetworkCredential(username, password);
XmlReaderSettings settings = new XmlReaderSettings();
settings.XmlResolver = resolver;
XmlReader reader = XmlReader.Create("https://mail.google.com/mail/feed/atom/", settings);
XDocument doc = System.Xml.Linq.XDocument.Load(reader);
var entries = from x in doc.Elements().First().Elements() where x.Name == "entry" select x;
In this case entries will be empty because all of the elements have the namespace automatically appended to them. If I change x.Name to x.Name.LocalName or namespace+x.Name then it works.
I’d like to prevent XmlReader from automatically appending namespaces, and query the xml how it was originally sent to me — without namespaces.
It is unlikely that XmlReader “automatically append namespaces”, as it normally never modifies content of XML. I think all nodes already have namespaces (if you post sample XML it could be confirmed), so you have to deal with it.
You options: just use namespaces or convert XML by moving nodes to namespace of your choice.