// A "functional" approach to build an
// XML element in memory.
XElement inventory =
new XElement("Inventory",
new XElement("Car", new XAttribute("ID", "1"),
new XElement("Color", "Green"),
new XElement("Make", "BMW"),
new XElement("PetName", "Stan")
)
);
// Call ToString() on our XElement.
Console.WriteLine(inventory);
}
Here, notice that the constructor of the inventory XElement object is in fact a tree of additional
XElements and XAttributes. Also note that by mindfully indenting our code statements, our code
base has a similar look and feel to the XML document itself. If we call our method from within
Main(), we find the output shown in Figure 24-10.
C H A P T E R 2 4
Do'stlaringiz bilan baham: |