7.7. Using LINQ to Create and Query XML

LINQ to XML uses LINQ syntax to generate, read, and sort XML data. LINQ to XML uses its own set of objects, such as XDocument, XElement, and XAttribute to represent parts of an XML document. It isn't quite as straightforward as regular LINQ, but as you can see in the next few paragraphs, the basic techniques are the same.

In this section, you build a class that holds information about family members (nieces and nephews). Next, you create objects from the class and configure the object properties.

The objects become the data source for an XML document that you save to a file on the Web server. In the final phase, you read the XML file and filter its data via LINQ syntax.

7.7.1. Creating the KinFolk class

The KinFolk class represents a niece or a nephew. To keep the code short, you record only the person's first name, gender, and father's name.

The KinFolk class uses the private variables _fname, _gender, and _father as well as the corresponding public properties Fname, Gender, and Father. To create the KinFolk class, follow these steps:

  1. Add a class file named kinfolk.vb to the App_Code folder of your project (FileNew FileClassAdd).

  2. Use contents ...

Get ASP.NET 3.5 For Dummies® now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.