linq-to-xml

Save attribute value of xml element with single quotes using linq to xml.

How do I make the XDocument object save an attribute value of a element with single quotes? ...

Validating and Extracting XML record by record into Database

Here's the deal. I have an XML document with a lot of records. Something like this: print("<?xml version="1.0" encoding="utf-8" ?> <Orders> <Order> <Phone>1254</Phone> <City>City1</City> <State>State</State> </Order> <Order> <Phone>98764321</Phone> <City>City2</City> ...

convert XmlNode to XNode?

Anyone know off the top of their heads how to convert a System.Xml.XmlNode to System.Xml.Linq.XNode? ...

LINQ to XML optional element query

I'm working with an existing XML document which has a structure (in part) like so: <Group> <Entry> <Name> Bob </Name> <ID> 1 </ID> </Entry> <Entry> <Name> Larry </Name> </Entry> </Group> I'm using LINQ to XML to query the XDocument to retrieve all these entries as follows: var items = from g in...

Merge XML files in a XDocument

Hello, I am trying to merge several XML files in a single XDocument object. Merge does not exist in XDocument object. I miss this. Has anyone already implemented a Merge extension method for XDocument, or something similar ? ...

LinqToXML XElement to XmlNode

HI, Is there any 'correct' way to convert an XElement to an XmlNode in C# - LinqToXML makes it nice to build the required XML programmatically but SharePoint web services requires an XmlNode, so whats the best way to mix and match? ...

LINQ: Get attribute with any namespace but specific name

Hi All, I need to be able get a single specific attribute from an element with a specific local name but any namespace (if you are familiar with XMPP you will understand why). Apart from writing my own (enumerator or single select) extension methods, any ideas? I have the following, but I don't like it at all: XAttribute from ...

Why isn't this LINQ to XML Query Working (Amazon S3)

Given this XML ... <ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"&gt; <Name>public.rpmware.com</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> <Contents> <Key>0.dir</Key> <LastModified>2008-06-25T16:09:49.000Z</LastModified> <ETag>"0ba2a466f9dfe225d7ae852...

What's the most efficient way to locate and set element values in an XDocument?

Given the following XML 'template': <Request module="CRM" call="list_service_features" id="{ID}"> <block name="auth"> <a name="username" format="text">{USERNAME}</a> <a name="password" format="password">{PASSWORD}</a> <a name="client-id" format="counting">{CLIENT-ID}</a> </block> <a name="service-id" format="countin...

Advice on the best way to structure/format a LINQ to XML query?

I have written a LINQ to XML query that does what I want, but it looks pretty ugly. I am wondering, how would you guys format the following query in a way that doesn't look quite so garish? Apologies if my example is a bit verbose. The XML documents I am querying have the following structure: <?xml version="1.0" encoding="iso-8859-1"...

How to use Linq to set attributes based on counter

Say I have a xml document that looks like this <foo> <bar id="9" /> <bar id="4" /> <bar id="3" /> </foo> I would like to use linq to reset the id's to 0, 1 ,2. What would be the easiest way to do this? Thanks ...

Extract a Byte[] from an XElement with Linq to Xml

Hi, I am saving some small images to Xml as a Byte[] via the following XElement construct.. XElement xe = new XElement("Images", from c in qry select new XElement("Image", new XAttribute("Date", c.Date), new XElement("Data", c.Bytes))); the Bytes property is a Byte[], looking at the resulting elem...

LINQ to XML Newbie Question: Returning Nodes By Node Name

Greetings! If I have XML such as this: <Root> <AlphaSection> . . . </AlphaSection> <BetaSection> <Choices> <SetA> <Choice id="choice1">Choice One</Choice> <Choice id="choice2">Choice Two</Choice> </SetA> <SetB> <Choice ...

Linq to XML - update/alter the nodes of an XML Document

Hello! If got 2 Questions: 1. I've sarted working around with Linq to XML and i'm wondering if it is possible to change a XML document via Linq. I mean, is there someting like XDocument xmlDoc = XDocument.Load("sample.xml"); update item in xmlDoc.Descendants("item") where (int)item .Attribute("id") == id ... 2. I already know how ...

Reading xml file from a resource

I am trying to load an xml file that is stored as a resource in my C# project so I can perform various LINQ queries. However at runtime an "Illegal characters in path" exception is thrown. This is how I am loading the file: XDocument doc = XDocument.Load(MyProject.Properties.Resources.XMLFile); ...

LINQ to XML Newbie Question: Returning Nodes Values AND Decendant Values

Greetings! I have some XML like this: <Root> <AlphaSection> . . . </AlphaSection> <BetaSection> <Choices> <SetA> <Choice id="choice1"> <Title>Choice 1 Title</Title> <Body>Choice 1 Body</Body> </Choice> <...

Binding XML in Sliverlight without Nominal Classes

Lets say I have a simple chunck of XML:- <root> <item forename="Fred" surname="Flintstone" /> <item forename="Barney" surname="Rubble" /> </root> Having fetched this XML in Silverlight I would like to bind it with xaml of this ilke:- <ListBox x:Name="ItemList" Style="{StaticResource Items}"> <ListBox.ItemTemplate> <...

Select unique XElements (by attribute) with a filter using LinqToXml

I have an XML document looking similar to this: <items> <item cat="1" owner="14">bla</item> <item cat="1" owner="9">bla</item> <item cat="1" owner="14">bla</item> <item cat="2" owner="12">bla</item> <item cat="2" owner="12">bla</item> </items> Now I'd like to get all unique owners (I actually only need the attribute value of the ...

How do I make LINQ to XML and HTML work together?

I have an html table <table border="0" width="100%"> <tr class="headerbg"> <th width="5%"> No </th> <th width="30%"> Name </th> <th width="20%"> Department or Division </th> <th width="25%"> ...

Find frequency of values in an Array or XML (C#)

I have an XML feed (which I don't control) and I am trying to figure out how to detect the volume of certain attribute values within the document. I am also parsing the XML and separating attributes into Arrays (for other functionality) Here is a sample of my XML <items> <item att1="ABC123" att2="uID" /> <item att1="ABC345" att2="uID...