RSS

Monthly Archives: June 2012

Reading an XML file using Linq to XML

A quick and post and more for my own reference but I recently needed to read some elements from an XML document which can be accomplished much easier these days using Linq to XML.

So if I have a simple XML document :

Sample XML document

I can read this using Linq as below (language is C#) :

C# routine to parse the XML document using Linq

In this method I am first loading the XML file into an XDocument Object found under the System.XML.Linq namespace.

I am then using Linq to return a collection of Items which represent the Parent ‘Client’ Nodes, using the Descendants function.

Then we can loop though each Client Node and simply extract the Element Values for the KEY and POSITION Nodes.  Its also worth noticing in this example that I have included an attribute at the CLIENT Node level.  Using Attributes().First() I am requesting the first attribute found attached to my CLIENT object.

Like I mentioned nothing difficult here but a handy little reference

 
Leave a comment

Posted by on June 22, 2012 in C#, Linq, Uncategorized, XML

 

LayerTwo – Simple Framework

For anyone that is looking to develop smartly styled and interactive interfaces for their Web sites then the new Simple Framework designed and developed by LayerTwo is well worth a look plus its completely free to download and use.

Leverage the power of Simple Framework with some great looking templates already available

Built on the 960 Grid System, the Simple Framework provides the HTML structure, basic styling and common jQuery components out of the box so you can dive straight into designing great looking websites in just a few seconds.

Available at www.layertwo.co.uk

 
Leave a comment

Posted by on June 20, 2012 in web development