As we saw in the previous section, we can convert XML to a different data structure and different data structure to XML. For example, the following code creates an XML tree with Icecreams
as the root element:
// Create XML Tree using XElement XElement ClassicIcecreams = new XElement("Icecreams", new XElement("Icecream", new XElement("Name", "Chocolate Fudge Icecream"), new XElement("Cholesterol", "50mg"), new XElement("TotalCarbohydrates", "35g"), new XElement("Protein", new XAttribute("VitaminA", "3g"), new XAttribute("Iron", "1g")), new XElement("TotalFat", new XAttribute("SaturatedFat", "9g"), new XAttribute("TransFat", "11g")) ) ); // Add new type of Icecream to the existing XML ClassicIcecreams.Add( new XElement("Icecream", new XElement("Name", "Vanilla Icecream"), new XElement("Cholesterol", "65mg"), new XElement("TotalCarbohydrates", "26g"), new XElement("Protein", "4g", new XAttribute("VitaminA", "1g"), new XAttribute("Calcium", "2g"), new...