linq-to-xml

XML Serialization vs LINQ to XML

Hi, I have few questions on XML serialization and LINQ to XML. When do we use XML Serialization and LINQ to XML? Please specify the kind of situations or scenarios to use XML Serialziation and LINQ to XML. What are the differences between XML Serialization and LINQ to XML? What are the benefits of using XML Serialziation over LINQ t...

XML Update Nodes using Linq

I have a xml file with following entries, I want to update. I have gone through other related questions but not solving my issue. <Movie> <Name>21</Name> <Year>2008</Year> <Genre>Drama</Genre> </Movie> ...

Linq select a range between letters, eg. a-e

Hi there, I want to create a list out of an xml file where only values between two letters are displayed. For example, only show matching records where the first character of the title are in the range from "A" to "E". My first basic approach was where item.Element("title").Value >= "A" && item.Element("title").Value < "E" Of cours...

Updating Linq to XML element values concatination issues

I am trying to write a app.config / web.config error correcting app that will audit our developers applications for incorrect environment settings. I am using Linq to XML to accomplish this and I am hitting a snag. var query = from el in doc.Descendants().Element("SMTPHost") select el; foreach (XElement host in query) { ...

Proper usage of xml file-based storage as database alternative in ASP.NET site

I'm building a small application and to reduce hosting costs and dependencies, I am planning to store all persistent data to xml files rather than a Sql Server database. In this case, the site audience is limited to friends and family - no more than a few concurrent users are ever expected, so the site does not need to scale. Is it fea...

Load repetitively-named XML nodes using Linq [C#]

Hello, I'm working on a program that needs to be able to load object-properties from an XML file. These properties are configurable by the user and XML makes sense to me to use. Take the following XML document. <?xml version="1.0" encoding="utf-8" ?> <udpcommands> <command name="requser"> <cvar name="reqchallege" value="false"...

Converting Linq to XML result to generic list in VB.Net. Odd error.

I have a function that works great in C# that I'm converting to VB.Net. I'm having an issue converting the result set to a generic list in VB.net. The code: Public Function GetCategories() As List(Of Category) Dim xmlDoc As XDocument = XDocument.Load("http://my_xml_api_url.com") Dim categories = (From category In xmlDoc.Descendan...

Does LINQ to XML replace XSLT?

Is there anything you can do in XSLT that can't be done in LINQ to XML? Is it still important to learn XSLT? When would you choose one over the other? ...

Problem in LINQ Query

In my table I am having my client Id as Actual Input:- <client> <ClientId>421</ClientId> <Amount>100</Amount> <client> <client> <ClientId>426</ClientId> <Amount>200</Amount> <client> <client> <ClientId>421</ClientId> <Amount>300</Amount> <client> <client> <ClientId>427</ClientId> <Amount>400</Amount> <c...

xml element name with colon

I'm working against a 3rd party xml api. They have defined a required xml structure similar to the following. <ns1:E xmlns:ns1="schema"> <ns1:B> <ns2:S> <ns2:V> <ns2:Bl /> </ns2:V> </ns2:S> </ns1:B> </ns1:E> There is a SQL table with the information that I need to put into this xml format. I have a LINQ to SQL adapter to ge...

Using LINQ to XML to build a collection - only getting the top item for some reason

So I'm trying to parse some XML from the twitter API and for some reason the LINQ query below only returns 1 row. When I step through the code to view the raw XML it's the usual 20+ items so I'm not sure what I'm doing wrong here. Any help for a LINQ to XML newbie? List<TwitterStatus> StatusCollection = new List<TwitterS...

Checking an XElement for Existence of One of Several Possible XElements

Is there a way to determine if an XElement contains one of any specified elements? For example, I have XElements that I'll want to check: Dim xe1 = <color><blue/></color> Dim xe2 = <color><red/></color> Dim xe3 = <color><powderBlue/></color> Dim xe4 = <color><aqua/></color> Dim xe5 = <color><green/></color> I'd like to be able to quer...

Help parsing GML data using C# Linq to XML

I know this is most likly very basic and been asked a thousand times but for some reason I just can't get it to work. I have a gml file that looks like the following: <?xml version='1.0' encoding='UTF-8'?> <schema xmlns='http://www.w3.org/2000/10/XMLSchema' xmlns:gml='http://www.opengis.net/gml' xmlns:xlink='http://www.w3.org/1999/xlin...

Converting Linq to XML query from C# to VB.Net. Can you spot my error?

I'm converting the Linq query below from C# to VB.Net. Can you spot my error? The query joins 3 XML datasets. Thanks in advance! C# - This one works great. List<Course> courses = (from course in CourseXML.Descendants(ns + "row") join coursecategory in CourseCategoryXML.Descendants("Table") on (string)course.Attribute("code") equals...

Help with with a traslation in Linq to Xml.

Can someone help with an explanation of what this means: ... .Select(Func<XElement, XElement>selector) Please an example of what should go in as parameter will be appreciated. Also found it a little bit difficult naming this question. Suggestion will also be appreciated. ...

How to implement IComparable to sort numerical and non-numerical string

How to implement IComparable to sort numerical and non-numerical string. Firstly, I want to get the Min and Max value in the "list". It is asking me to implement ICompareable. " At least one object must implement IComparable" Can anyone help me? Here is my code: // setup string filePath1 = Directory.GetCurrentDirector...

LINQ to XML: handling nodes that do not exist?

This may be a simple fix (well, it probably is) but for some reason I just can't figure it out. So, I have some xml that looks something like this: XElement xml = XElement.Parse ( @"<Alphabet> <a name="A" /> <b name="B" /> <d name="D" /> <e name="E" /> </Alphabet>"); So later in my code, I reference a node that ma...

LINQ to XML query (basic)

Hi I am new to LINQ I have an xml in the following format "<root>" "<page>" "<title>text</title>" "<text attrib1="1">some text</text>" "<text attrib1="2">some text</text>" "<text attrib1="3">some text</text>" "<text attrib1="4">some text</text>" "</page>" "<page>" "<title>text</title>" "<text attrib1=...

Is there an advantage of Linq to XML over serializing and deserializing classes to XML?

If I want to work with XML, I usually design a class/bunch of classes that represent the data I need. Then I use XmlSerializer to read in the XML and write it out again. This gives me strongly typed classes to work with whilst the XML is "in memory". I can of course use Linq on these classes without any issue. Should I be using Linq t...

Linq to XML: How do you determine if something of type "var" is null or empty?

So, I've got a small chunk of stabby, pointy xml that looks like this: <Groups UseGroup='True'> <Group>1264,182,1979</Group> </Groups> And I've got a small chunk of linq that gets the value from that looks like this: var group = from a in xml.Descendants("Groups") select a.Element("Group").Value; It's all fine and dandy...