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 :
I can read this using Linq as below (language is C#) :
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