24.3. Working with XElement and XDocument

Let's continue the investigation of LINQ to XML with a new Console Application named ConstructingXmlDocs. Once you have done so, import the System.Xml.Linq namespace in your initial code file. As you have already seen, XDocument represents the entirety of an XML document in the LINQ to XML programming model, as it can be used to define a root element, and all contained elements, processing instructions and XML declarations. Here is another example of building XML data using XDocument:

static void CreateFullXDocument() { XDocument inventoryDoc = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XComment("Current Inventory of cars!"), new XProcessingInstruction("xml-stylesheet", "href='MyStyles.css' ...

Get Pro C# 2010 and the .NET 4 Platform, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.