i am using linq-to-xml to search elements.
var doc = XDocument.Load(reader);
var ns = doc.Root.Attribute("xmlns").Value;
var result = (from u in doc.Descendants(XName.Get("MyElement", ns))
i need to get rid of using XName.Get whenever i try to find an element in xml. how can i set a default namespace to XDocument so that it will not bother when searching.
Regards.
Here is one way of ignoring default namespaces, if you really want to do that:
But I would suggest to accept the existence and importance of namespaces in XML and use the XName and XNamespace objects LINQ to XML provides to work with them.