// Now enumerate over the array to build
// an XElement.
XElement vehicles =
new XElement("Inventory",
from c in data
select new XElement("Car",
new XAttribute("ID", c.ID),
new XElement("PetName", c.PetName)
)
);
Console.WriteLine(vehicles);
}
Loading and Parsing XML Content
The XElement and XDocument types both support Load() and Parse() methods, which allow you to
hydrate an XML object model from string data or external files. Consider the following method,
which illustrates both approaches:
C H A P T E R 2 4
■
P R O G R A M M I N G W I T H T H E L I N Q A P I S
861
8849CH24.qxd 10/19/07 10:11 AM Page 861
static void LoadExistingXml()
{
Do'stlaringiz bilan baham: |