linq-to-xml

How do I serialise a List<T> to XML using LINQ to XML?

I've this generic list List<zil> listKD = new List<zil> { new zil{day="Mon",c="1",S1="08:00",S2="08:40",S3="08:47"}, new zil{day="Mon",c="2",S1="08:50",S2="09:30",S3="09:37"}, new zil{day="Mon",c="3",S1="09:40",S2="10:20",S3="10:27"}, new zil{day="Mon",c="4",S1="10:30",S2="1...

XML with C# linq-xml

Following is the example of an XML document <People> <Person> <Name>ABC </Name> <SSN>111111</SSN> <Address>asdfg</Address> </Person> </People> I need to get the Tag names but not the values between the tag names. i.e., Under Person Tag, I should grab the Name, SSN, Address nodes and not the ABC, 111111, asd...

LINQ to XML NullReferenceException AFTER returning the results??

Hi! I'm quite new to .NET and even more so to LINQ, which I have just begun exploring for a small project I'm working on. I have a XML file generated from an application that contains a few values that I want to parse into a proprietary format and save in a file. I'm able to make one LINQ query work fine, returning values to my Console...

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 efficient method to convert XML between XDocument and XmlDocument? (Without using any te...

Silverlight 3: Converting XML stroke collection back into a strokecollection?

I have a silverlight app that allows the user to draw on it and save the drawing. The strokecollection in the canvas is converted to xml attributes and stored in the database. the only problem i have now is converting the xml back into a stroke collection. my strokes are stored as such: <Strokes> <Stroke> <Color A="255"...

Creating XML in C# for jQuery

I'm trying to generate some XML for a jQuery.get (AJAX) call, and I'm getting the following error from my C# page: "Using themed css files requires a header control on the page. (e.g. <head runat="server" />)." The file generating the XML is a simple .aspx file, consisting entirely of: <%@ Page Language="C#" AutoEventWireup="true" Code...

ISNULL() in LINQ to XML

Dear All, SELECT * FROM CUSTOMERS WHERE RTRIM(ISNULL([SHORTNAME],'')) LIKE '%john%' I want to write this using Linq, var persons = from person in xmlDoc.Descendants("Table") where person.Element("SHORTNAME").Value.Contains("123") select new { shortName = person.Element("SHORTNAME").Value, longName = person.Element("LONGNAME").Va...

Is this the most efficient way of loading xml values into a structure?

I am trying to load data from XML string into a structure of some sort so once loaded I can then say Data.PropertyName to read the values. Is the below code the most optimal way of loading the data into the structure? Obviously calling First() has a memory hit so if you have elements with sub elements will calling First() for each ...

Help Merging XML Data

I have two XMLDocuments that contain some similar information but there are other nodes that contain different information between the two. I am using XMLSerialization to put my data into a structure as shown here I know you can merge XML files by using a DataSet as shown here but I want to somehow serialize the first document I see in...

Why can't I set the XDocument XDeclaration encoding type to iso-8859-1?

Why doesn't the following code set the XML declaration encoding type? It always sets the encoding to utf-16 instead. Am I missing something very obvious? var xdoc = new XDocument( new XDeclaration("1.0", "iso-8859-1", null), new XElement("root", "") ); output: <?xml version="1.0" encoding="utf-16"?> <root></root> ...

DeSerialize DataTable Row Collection into List<T>

I have a DataTable with rows of data. I have a class with properties that match the row column names. How can I have a List that is populated from the DataTable Row information? Do I call something like (MyType)new XmlSerializer(typeof(MyType)).Deserialize(new XMLReader(Table.WriteXML())); ...

how to get root node attribute value using linq

Hi, I have the following XML. How to read the root node attribite value and it's decendents using LINQ? I am trying to read "dId" and "dTime" from root node, "id" from Customer element and Order number. <?xml version="1.0" encoding="utf-8" ?> <Customers dId="wqwx" dTime="10-9-09 11:23"> <Customer id="1"> <Orders> <Orde...

How to search for a node using Linq to XML Query?

Below the xml doc <Root> <Global> </Global> <local> <section name="A"> <subsection name="A"> <innersection name="A"> <Property1> </Property1> </innersection> <innersection na...

LINQ to XML And Distinct Custom Class

I have a very interesting LINQ question. I have a document, that I am trying to filter results on, but to filter, I am matching on a REGEX result from one element of the XML. I have the following, working LINQ to XML to get the individual data that I'm looking for. Dim oDocument As XDocument oDocument = XDocument.Load("test.xml") Dim ...

LINQ to XML: applying an XPath

Can someone tell me why this program doesn't enumerate any items? Does it have something to do with the RDF namespace? using System; using System.Xml.Linq; using System.Xml.XPath; class Program { static void Main(string[] args) { var doc = XDocument.Load("http://seattle.craigslist.org/sof/index.rss"); foreach (...

Return value from XPathSelectElement(s) in C#

How do node.XPathSelectElement() and node.XPathSelectElements() behave when the selection is either not a NodeSet or a NodeSet containing non-Elements? For example do they always return something or can they throw Exceptions? can the return value be null or is it always an IEnumerable of some sort? The XML searched is constant: <a> <b...

struggling with XML namespaces (linq)... what am I doing wrong here?

Hi, Trying to parse some XML but apparently this is too much for a lazy sunday afternoon, this is my code: (I Tried the XPathDocument and XmlDocument approach too but this also failed miserably) XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(postData); XDocument xDoc = XDocument.Load(new XmlNodeReader(xmlDoc)); XNamespac...

How do I generate a linq to xml infoset w/ a DTD reference?

I need to generate an xml infoset but the infoset needs to contain a reference to a client's DTD. The desired out needs to contain this DTD reference <!DOCTYPE AutoApplication SYSTEM "http://www.clientsite.com/public/DTD/autoappV1-3-level2.dtd"&gt; This reference sits directly benath the xml declaration. Neither XProcessingInstruction...

Linq XML Dynamic building.

I am building an xml file. Parts of the file are static. Some of the file is dynamic. My code has an error of “Null object reference”. Any tips would be awesome. private XElement BuildDataElement() { // this is going to be more complicated return new XElement("data"); } public void TestXML(string fname) { // b...

Linq to XML -Dictionary conversion

How to store the nodes of the following into Dictionary where int is an autogenerated Key and string (value of the node) using LINQ ? Elements: XElement instructors = XElement.Parse( @"<instructors> <instructor>Daniel</instructor> <instruct...