Questions tagged [linq-to-xml]

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

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

Related Links

5019 questions
592
votes
7 answers

XDocument or XmlDocument

I am now learning XmlDocument but I've just ran into XDocument and when I try to search the difference or benefits of them I can't find something useful, could you please tell me why you would use one over another ?
Tarik
  • 79,711
  • 83
  • 236
  • 349
383
votes
4 answers

Populate XDocument from String

I'm working on a little something and I am trying to figure out whether I can load an XDocument from a string. XDocument.Load() seems to take the string passed to it as a path to a physical XML file. I want to try and bypass the step of first having…
StevenMcD
  • 17,262
  • 11
  • 42
  • 54
212
votes
6 answers

LINQ to read XML

I am using this XML file:
Aximili
  • 28,626
  • 56
  • 157
  • 216
200
votes
6 answers

Converting XDocument to XmlDocument and vice versa

It's a very simple problem that I have. I use XDocument to generate an XML file. I then want to return it as a XmlDocument class. And I have an XmlDocument variable which I need to convert back to XDocument to append more nodes. So, what is the most…
Wim ten Brink
  • 25,901
  • 20
  • 83
  • 149
199
votes
2 answers

What is the difference between Linq to XML Descendants and Elements

I have came across both these keywords in the VS IntelliSense. I tried to googling the difference between them and did not get a clear answer. Which one of these have the best performance with small to medium XML files. Thanks
Luke101
  • 63,072
  • 85
  • 231
  • 359
163
votes
3 answers

How to get a JSON string from URL?

I'm switching my code form XML to JSON. But I can't find how to get a JSON string from a given URL. The URL is something like this: "https://api.facebook.com/method/fql.query?query=.....&format=json" I used XDocuments before, there I could use the…
ThdK
  • 9,916
  • 23
  • 74
  • 101
154
votes
10 answers

Query an XDocument for elements by name at any depth

I have an XDocument object. I want to query for elements with a particular name at any depth using LINQ. When I use Descendants("element_name"), I only get elements that are direct children of the current level. I'm looking for the equivalent of…
Rich
  • 36,270
  • 31
  • 115
  • 154
145
votes
1 answer

How to put attributes via XElement

I have this code: XElement EcnAdminConf = new XElement("Type", new XElement("Connections", new XElement("Conn"), // Conn.SetAttributeValue("Server", comboBox1.Text); // Conn.SetAttributeValue("DataBase", comboBox2.Text))), new…
Dominating
  • 2,890
  • 7
  • 25
  • 39
118
votes
4 answers

how to use XPath with XDocument?

There is a similar question, but it seems that the solution didn't work out in my case: Weirdness with XDocument, XPath and namespaces Here is the XML I am working with:
jojo
  • 13,583
  • 35
  • 90
  • 123
117
votes
9 answers

XDocument.ToString() drops XML Encoding Tag

Is there any way to get the xml encoding in the toString() Function? Example: xml.Save("myfile.xml"); leads to xxx Allianz…
Henrik P. Hessel
  • 36,243
  • 17
  • 80
  • 100
93
votes
7 answers

The ':' character, hexadecimal value 0x3A, cannot be included in a name

I have an xml file that contains its element like Str When I am trying to access it using the code: XElement tempElement = doc.Descendants(XName.Get("ab:test")).FirstOrDefault(); It's giving me this…
coure2011
  • 40,286
  • 83
  • 216
  • 349
90
votes
2 answers

XML file creation using XDocument in C#

I have a List "sampleList" which contains Data1 Data2 Data3... The file structure is like
Thorin Oakenshield
  • 14,232
  • 33
  • 106
  • 146
85
votes
8 answers

How to get Xml as string from XDocument?

I am new to LINQ to XML. After you have built XDocument, how do you get the OuterXml of it like you did with XmlDocument?
Ashish Gupta
  • 14,869
  • 20
  • 75
  • 134
84
votes
5 answers

How do I do a deep copy of an element in LINQ to XML?

I want to make a deep copy of a LINQ to XML XElement. The reason I want to do this is there are some nodes in the document that I want to create modified copies of (in the same document). I don't see a method to do this. I could convert the…
Daniel Plaisted
  • 16,674
  • 4
  • 44
  • 56
83
votes
6 answers

How to use XPath with XElement or LINQ?

Consider the following XML: 200 OK http://bit.ly/b47LVi b47LVi 9EJa3m
Paul Fryer
  • 9,268
  • 14
  • 61
  • 93
1
2 3
99 100