Top "Linq-to-xml" questions

LINQ-to-XML provides a SQL-like query experience for navigating, parsing, and aggregating data stored in XML documents.

How do I add an XElement to a document, avoiding the "incorrectly structured document" error?

// Remove element with ID of 1 var userIds = from user in document.Descendants("Id") where user.Value == "1" select user; userIds.Remove(); …

c# .net xml linq-to-xml
How to add child element to XElement as a decoded string?

I want to make pass this test. What should I use instead of Add method? [TestMethod] public void AddContentWithoutEncoding() { var …

c# .net xml linq-to-xml xelement
Is there an easy way to compare if 2 XDocuments are equal ignoring element/attribute order?

Unit testing my serialization code I found one failed because I had attributes listed in a different order (I'm just …

c# xml linq-to-xml
XDocument.Descendants() versus DescendantNodes()

I've looked at Nodes() vs DescendantNodes() usages? to see the difference between .Nodes() and .DescendantNodes() but what is the difference …

c# xml linq-to-xml
XDocument and Linq returns null if the element has xmlns attribute

Newbie with XDocuments and Linq, please suggest a solution to retrieve the data from a particular tag in the xml …

c# xml linq-to-xml
How to best detect encoding in XML file?

To load XML files with arbitrary encoding I have the following code: Encoding encoding; using (var reader = new XmlTextReader(filepath)) { …

encoding linq-to-xml xmlreader xelement
XDocument.Descendants() not returning any elements

I'm trying to bind a Silverlight DataGrid to the results of a WCF service call. I was not seeing the …

silverlight wcf-binding linq-to-xml
Unexpected exception from XDocument constructor

This works fine: XDocument xdoc = new XDocument( new XDeclaration("1.1", "UTF-8", "yes"), new XProcessingInstruction("foo", "bar"), new XElement("test")); However if …

c# .net linq-to-xml
Weirdness with XDocument, XPath and namespaces

I have an XML document that looks like this: <kmsg xmlns="http://url1" xmlns:env="url1" xmlns:xsi="http://…

c# xpath linq-to-xml xml-namespaces
Cannot implicitly convert type System.Collections.Generic.Dictionary<System.Tuple<int,int,string>, AnonymousType#1>

I have the following dictionary in a method: var nmDict = xelem.Descendants(plantNS + "Month").ToDictionary( k => new Tuple<…

c# linq-to-xml idictionary