Return to Snippet

Revision: 21638
at December 16, 2009 18:57 by pckujawa


Initial Code
<?xml version="1.0" encoding="utf-8" ?>
<Tutorials>
  <Tutorial>
    <Author>The Reddest</Author>
    <Title>
      Creating an XP Style WPF Button with Silverlight
    </Title>
    <Date>2/20/2008</Date>
  </Tutorial>
  <Tutorial>
    <Author>The Fattest</Author>
    <Title>
      Flex And Yahoo Maps
    </Title>
    <Date>2/12/2007</Date>
  </Tutorial>
  <Tutorial>
    <Author>The Tallest</Author>
    <Title>
      WPF Tutorial - Creating A Custom Panel Control
    </Title>
    <Date>2/18/2008</Date>
  </Tutorial>
</Tutorials>

XDocument xmlDoc = XDocument.Load("TestFile.xml");

var tutorials = from tutorial in xmlDoc.Descendants("Tutorial")
                select new
                {
                  Author = tutorial.Element("Author").Value,
                  Title = tutorial.Element("Title").Value,
                  Date = tutorial.Element("Date").Value,
                };

Initial URL
http://www.switchonthecode.com/tutorials/introduction-to-linq-simple-xml-parsing

Initial Description
See the URL.

Initial Title
Simple XML parsing using LINQ (create an anonymous or real object from XML data)

Initial Tags
xml

Initial Language
C#