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
20
votes
3 answers

XPath and XPathSelectElement

I have the following xml I've tried everything to read the name of the db2 (="Name2") with all possible…
gsharp
  • 27,557
  • 22
  • 88
  • 134
20
votes
2 answers

How to get an independent copy of an XDocument?

I'm trying to create a new XDocument as follows: var xmlString = _documentDictionary[documentKey].ToString(SaveOptions.DisableFormatting); XDocument xml = XDocument.Parse(xmlString); I now have xml which I would have though was a stand-alone…
DaveDev
  • 41,155
  • 72
  • 223
  • 385
20
votes
3 answers

XML parse check if attribute exist

I've made a method which checks if an attribute exist in a XML-file. If it does not exist it returns "False". It works but it takes a very long time to parse the file. It seems it reads the whole file for each single row. Have I missed something…
Joe
  • 4,274
  • 32
  • 95
  • 175
20
votes
5 answers

LINQ to XML: how do I get only direct descendants of an XElement?

Dim xml = Thomas Tim Jamie Dim…
Rob Sobers
  • 20,737
  • 24
  • 82
  • 111
19
votes
3 answers

Linq to Xml : Exception -The ' ' character, hexadecimal value 0x20, cannot be included in a name

This is my Entity Class with an Entity : [Table(Name = "CLINICAL_ITEM_MASTER")] public class ClinicalItemMaster { [Column] public int CLIENT_INPUT_MHS_ID { get; set; } [Column] public Guid CLIENT_INPUT_MHS_GUID { get; set; } …
MSanika
  • 1,311
  • 5
  • 13
  • 21
19
votes
3 answers

How do you handle arbitrary namespaces when querying over Linq to XML?

I have a project where I am taking some particularly ugly "live" HTML and forcing it into a formal XML DOM with the HTML Agility Pack. What I would like to be able to do is then query over this with Linq to XML so that I can scrape out the bits I…
bouvard
  • 3,864
  • 25
  • 29
19
votes
2 answers

XDocument get XML element by the value of its name attribute

I have an XML result like this 0 16
kbaccouche
  • 4,575
  • 11
  • 43
  • 65
18
votes
3 answers

Jaxb equivalent in C#

Using JAXB in Java it is easy to generate from a xml schema file a set of Java classes that xml conforming to that schema can be deserialized to. Is there some C# equivalent of JAXB? I know that Linq can serialize and deserialize classes to/from xml…
mgamer
  • 13,580
  • 25
  • 87
  • 145
18
votes
6 answers

Convert single XElement to object

I have a single XElement looking like this: Then I have a class looking like this: public class ProductAttribute { public string Flag { get; set; } public string Sect { get; set; } …
Numm3n
  • 1,021
  • 2
  • 9
  • 26
18
votes
2 answers

Query XDocument with xmlns attribute (namespace)

I try to query elements from an visual studio *.csproj file. I created a short example to illustrate the problem: // Working string xml1 = @"
Joel
  • 4,862
  • 7
  • 46
  • 71
18
votes
3 answers

How to convert XML to Dictionary

I've xml as following: Log In Password I success to do that without Linq, any one can help me to convert the following code to…
Ramzy Abourafeh
  • 1,195
  • 7
  • 17
  • 35
18
votes
2 answers
18
votes
1 answer

how to Check if a XML child element exists with Linq to XML

How can I check if IncomingConfig element exists by use linq to xml? 10.100.101.18 5060 tarek
Tarek Saied
  • 6,482
  • 20
  • 67
  • 111
17
votes
2 answers

Best way to query XDocument with LINQ?

I have an XML document that contains a series of item nodes that look like this: lorem ipsum 123
snappymcsnap
  • 2,050
  • 2
  • 29
  • 53
17
votes
2 answers

Why is my XDocument saving the declaration when I don't want it to?

I have the following code: class Program { static void Main(string[] args) { using (var stream = File.Create(@"C:\test.xml")) { var xml = new XElement("root", new…
KallDrexx
  • 27,229
  • 33
  • 143
  • 254