linq-to-xml

Is there an easy way to return the FIRST LinqToXML result?

Ok, I have a LinqToXml query that returns a single record (correct terminology?), however, I don't want to use a for.. loop to pull that one record from the query. Is there an easier way? *bonus if you find a better way to write the query (I'm still learning) my xml file: <?xml version="1.0"?> <!-- first draft of LibMappings.xml fi...

ASP.Net MVC XDocument Html.Decode/Encode Help

Can someone explain the best way to handle this approach. I am using TinyMCE editor. The information typed into this is loaded into a XDocument and then written to the database as a string by doing XDocument.ToString() When I output the content to a webpage I load the string from the database into a XDocument, find the element and do a...

Linq to Xml and creating elements

I have a string array: string[] authors = new string[3]; authors[0] = "Charles Dickens"; authors[1] = "Robert Jordan"; authors[2] = "Robert Ludlum"; I am using Linq to XML to read and write XML to a given XML file, but I cannot figure out how to use the XElement class to create XML that represents my authors array. I know it's someth...

XElement and List<g>

I have a class that has the following properties: public class Author { public string FirstName { get; set; } public string LastName { get; set; } } Next, I have a List of Authors like so: List<Author> authors = new List<Author> (); authors.add( new Author { FirstName = "Steven", LastName = "King" }); authors.add( ...

MVVM with XML Model and LinqToXml?

Hi, I've been reading up on the MVVM pattern, and I would like to try it out on a relatively small WPF project. The application will be single-user. Both input and output data will be stored in a "relational" XML file. A schema (XSD file) with Keys and KeyRefs is used to validate the file. I have also started to get my feet wet with Lin...

Can't load xmlreader into xdocument

Hi, I'm trying to load an xmlreader into an xdocument for easier manipulation. The xml is well formed and valid (I double checked). When I try and load it into the xdocument, I get an invalidopeationexception "The XmlReader state should be EndOfFile after this operation." the code to load this is public void ReadXml(System.Xml.XmlRea...

Linq to Xml noob question

I'm trying to parse an mvcSiteMap, I've got most of it working, but my where clause it not right. it always returns the row that the where clause should be excluding. nodeTitle = "Bulk Order Request"; XElement xelement2 = XElement.Load( filePath ); var urlDescList1 = (xelement2.Descendants() // Select node with 'Favorite Social Sit...

LINQ to XML + left join + group by = fail

I have two tables: block: int id, [other columns...] blockInstance: int id, int blockId (references Block.Id), [other columns...] My goal is to generate an enumeration of block objects with two properties: (1) Id (the Id of the Block) and (2) InstanceCount (the number of Instances for the Block). Currently, my XML file contains no Blo...

Query simple XDocument in LINQ

I'm probably doing something realy stupid but I cant get this to work: var xmlQuery = from i in doc.Descendants("Item") select new TriggerItem() { CreatedDate = DateTime.Now, ItemIdentifier = i.Attribute("itemCode").Value, Name = i.Attribute("name").Value, ProductIdentifier = (i.Attribute("productCode") != null) ? i.Attribut...

LINQ to XML vs. XmlReader

In my Silverlight application I'm using mostly XmlReader but I'm playing with idea to replace XmlReader implementation with LINQ to XML. What are pros and cons between LINQ to XML and XmlReader in Silverlight? ...

Linq to Xml: Complex query help

Assume i have the following XML data: <?xml version="1.0" encoding="utf-8" ?> <Accounts> <Account name="Account1"> <Campaign name="Camp1"> <RemoteCampaign>RC1</RemoteCampaign> <RemoteCampaign>RC2</RemoteCampaign> </Campaign> <Campaign name="Camp2"> <RemoteCampaign>RC3</RemoteCampaign> </Campaign...

using LINQ to XML to query inner xml of child nodes

Let's say that I've got this xml: <items> <item name="thumb"> <downloadStream>test1</downloadStream> <downloadStream>test2</downloadStream> <downloadStream>test3</downloadStream> </item> <item name="photo"> <downloadStream>test5</downloadStream> <downloadStream>test6</downloadStream> <downloadStream>test7</...

Inserting records into an XML table with a unique key

Hi, Maybe I'm just spoiled by SQL, but is there some cool LINQ way to insert a new record into an "XML table" and have the indexed ID update automatically (or at least semi-automatically)? Here's what I mean by "XML table": <myElements> <myElement> <id>1</id> <value>blah</value> </myElement> <myElement> <id>...

LINQ to XML - How to implement a simple XLink lookup - finding nodes anywhere

So we have an XML file with a very simple implementation of XLink: <root xmlns:xlink="http://www.w3.org/1999/xlink"&gt; <firstChild id="ID1" /> ... <ref xlink:href="#ID1" /> </root> Let's assume the XLink implementation won't get any more complicated than that. However the important point is that the element referred to (in this...

How do I group these XDocuments?

Problem I have a collection of XDocument instances. Each document has a repeated element that can take a different value. I want to group them by this value but each element can specify a different value. <sampledoc> <value>a</value> <value>b</value> <value>c</value> </sampledoc> Example Document A has values a, b, c Document...

how to extract maximum date from web page in dot net window application

hi In my application I want to extract the latest date shown in web page. I am using System.Xml.Linq.XDocument class to extract content. But I am not able to extract pubdate of feed. Here is my code but its giving exception. System.Xml.Linq.XDocument feeddata = System.Xml.Linq.XDocument.Load( "http://feeds2.feedburner.com/pla...

When querying with LINQ-to-XML, is it better/more efficient to leave element values as strings or convert them to the correct type?

I'm constantly running up against this when writing queries with LINQ-to-XML: the Value property of an XElement is a string, but the data may actually be an integer, boolean, etc. Let's say I have a "where" clause in my query that checks if an ID stored in an XElement matches a local (integer) variable called "id". There are two ways I ...

Checking if a XML child element exists with Linq to XML

Hi people, I'm trying to get my head around a problem I'm having in Linq to XML, seems like it should be pretty simple but even after browsing the Linq to XML questions here, I can't quite get it. Take something along the lines of the following XML: <users> <user id="1"> <contactDetails> <phone number="555 555 ...

Using Generics in Linq Query?

I am trying to write a generic function that generates an Xelement based on a list of objects, and a property of the object Currently I have this code copied and pasted in several spots InputElementsArray = New XElement(New XElement("ArrayInputs", _ New XElement("InputName", "TestFailedRefDesList"), _ ...

Loose merge of XML documents

I've got two documents - one is a custom XML file format, the other is an RSS feed with a bunch of custom extensions. I want to fill in fields in the XML file with values found in the RSS feed when one element value matches. This is for an offline process that will be run a few times manually - it doesn't need to perform well, be all th...