The XDocument can contain one root XElement, XComment, XDeclaration, and
XProcessingInstruction. For example:
XmlDocument Icecreams = new XmlDocument();
Other Classes
An XNode represents any item that is represented as a node in the XML
tree. XElements, XComments and XDocument, XDocumentType, and
XProcessingInstructions and XText are some of the nodes represented in the
XML tree.
The XComments class is used for adding comments to the XML.
XProcessingInstruction is for providing additional information to the application
that processes the XML data.
Chapter 3
[ 37 ]
Following is the code for adding some of the nodes to the XML:
// Adding Declaration, Comments and PI
XDocument IcecreamsDocument = new XDocument
(
new XDeclaration("1", "utf-8", "yes"),
new XComment("XML data Manipulation using LINQ"),
new XProcessingInstruction("Instructions", "12345-67890"),
new XElement("Icecreams",
new XElement("Icecream",
new XElement("Name", "Chocolate Fudge Icecream"),
new XElement("Ingredients", "cream, milk, sugar, corn syrup,
cellulose gum, mono and diglycerides.
Pages:
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72