linq-to-xml

Compare two xml and print the difference using LINQ

谁都会走 提交于 2019-12-18 15:54:38
问题 I am comparing two xml and I have to print the difference. How can I achieve this using LINQ. I know I can use XML diff patch by Microsoft but I prefer to use LINQ . If you have any other idea I will implement that //First Xml <Books> <book> <id="20504" image="C01" name="C# in Depth"> </book> <book> <id="20505" image="C02" name="ASP.NET"> </book> <book> <id="20506" image="C03" name="LINQ in Action "> </book> <book> <id="20507" image="C04" name="Architecting Applications"> </book> </Books> /

C# check an element exists while using LINQ to XML

久未见 提交于 2019-12-18 15:49:49
问题 OK, bit of a random question, but the best way to do this is to just add the code, you'll be able to see what I mean straight away: XML: <?xml version="1.0" encoding="utf-8" ?> <customers> <customer> <id>1</id> <name>Blah-face</name> <Type>1</Type> </customer> <customer> <id>2</id> <name>Blah-face-2</name> <Type>2</Type> </customer> <customer> <id>3</id> <name>Blah-face-3</name> <Type>1</Type> <SuperType>1</SuperType> </customer> </customers> C#: XDocument linquee = XDocument.Load(path); var

LINQ and XDocument: How to create XML file?

点点圈 提交于 2019-12-18 13:02:18
问题 I have a three List in c# ,the variable names are l_lstData1, l_lstData2, l_lstData3 . File structure is <FileDetails> <Date FileModified="29/04/2010 12:34:02" /> <Data Name="Data_1" DataList="India" Level="2" /> <Data Name="Data_2" DataList="chennai" Level="2" /> <Data Name="Data_3" DataList="hyderabad" Level="2" /> <Data Name="Data_4" DataList="calcutta" Level="2" /> <Data Name="Data_5" DataList="vijayawada" Level="1" /> <Data Name="Data_6" DataList="cochin" Level="1" /> <Data Name="Data_7"

The most efficient way to parse Xml

五迷三道 提交于 2019-12-18 11:47:43
问题 The .Net framework now has (at least) four different methods of reading an Xml string. I've used each of XmlDocument, XmlReader, XPath and XElement, but which is the most efficient to use when coding or during execution? Is each designed for a different task, what are the pros and cons? Update: Using a XmlReader appears to be the quickest way to read xml, which sound reasonable to me, but has it's limitations. I would like to know if there is any performance difference between XmlDocument and

load xelement into a datatable

点点圈 提交于 2019-12-18 09:39:16
问题 i have the following xml file, that contains a lot of Information about branches of a company .. (this is only an example).. what i really need, is to load only the data from Branch1 in a datatable(that has the same structure as my xml file, so no problem with the datatable at all) .. iam using c# and i would like to do this is linq, but i have no idea about linq... my question is: how would i read the entry from xml as a datatable row, so i can copy it to my datatable ? i now have: XElement

LinqToXml does not handle nillable elements as expected

杀马特。学长 韩版系。学妹 提交于 2019-12-18 07:08:50
问题 According to W3C standards, if you have a nillable element with a nil value, you are supposed to format it like this: <myNillableElement xsi:nil="true" /> But if you use this LinqToXml statement... element.Add( new XElement(ns + "myNillableElement", null); ...the resulting XML is... <myNillableElement /> ...which is invalid. And not just invalid according to W3C, invalid according to Microsoft's own XML/XSD validator. So, next time you validate your XML, you get errors. Am I missing some

unable to edit DataGridView populated with results of LINQ query

穿精又带淫゛_ 提交于 2019-12-18 07:02:22
问题 When i use the results of a linq-to-xml query to populate a datagridview, i cannot edit the datagridview. i've tried setting the datagridview's readonly property to false and that doesn't help. I also added an event handler for cellBeginEdit and put a breakpoint there, but it doesn't get hit. Any idea what i'm doing wrong, or if this isn't possible? public class MergeEntry { public string author { get; set; } public string message { get; set; } } ... var query = from entry in xmlDoc

unable to edit DataGridView populated with results of LINQ query

*爱你&永不变心* 提交于 2019-12-18 07:01:56
问题 When i use the results of a linq-to-xml query to populate a datagridview, i cannot edit the datagridview. i've tried setting the datagridview's readonly property to false and that doesn't help. I also added an event handler for cellBeginEdit and put a breakpoint there, but it doesn't get hit. Any idea what i'm doing wrong, or if this isn't possible? public class MergeEntry { public string author { get; set; } public string message { get; set; } } ... var query = from entry in xmlDoc

How to best detect encoding in XML file?

余生长醉 提交于 2019-12-18 05:54:36
问题 To load XML files with arbitrary encoding I have the following code: Encoding encoding; using (var reader = new XmlTextReader(filepath)) { reader.MoveToContent(); encoding = reader.Encoding; } var settings = new XmlReaderSettings { NameTable = new NameTable() }; var xmlns = new XmlNamespaceManager(settings.NameTable); var context = new XmlParserContext(null, xmlns, "", XmlSpace.Default, encoding); using (var reader = XmlReader.Create(filepath, settings, context)) { return XElement.Load(reader

This operation would create an incorrectly structured document

霸气de小男生 提交于 2019-12-18 05:42:16
问题 I am new to XML and tried the following but I'm getting an exception. Can someone help me? The exception is This operation would create an incorrectly structured document My code: string strPath = Server.MapPath("sample.xml"); XDocument doc; if (!System.IO.File.Exists(strPath)) { doc = new XDocument( new XElement("Employees", new XElement("Employee", new XAttribute("id", 1), new XElement("EmpName", "XYZ"))), new XElement("Departments", new XElement("Department", new XAttribute("id", 1), new