vbnet LINQ to XML

'XmlFile's structure
'        <Item>
'            <Name></Name>
'            <SubElements>
'                <Code></Code>
'            </SubElements>
'        </Item>

Dim feedXML As XDocument = XDocument.Load(XmlFile)
Dim feeds = From feed In feedXML.Descendants("Item") _
			Select Name = feed.Element("Name").Value, _
			SubElements = feed.Elements("SubElements")

For Each item In feeds
	Console.WriteLine(item.Name)

	For Each varItem In item.SubElements.Elements
		Console.WriteLine(varItem.Element("Code").Value)
	Next
Next
Example of LINQ to XML - which loads an .xml file and queries it, then loops through each item and its sub elements.

Updated: Sunday 10th October 2010, 10:55am

There are 0 comments

Leave a comment of your own

Comments are currently closed.