Generate an XML document using fluent syntax C# with Example



Generate an XML document using fluent syntax C# with Example

Goal: 
 
 
Banana 
Yellow 
 
 
Apple 
Red 
 
 

 
Code: 
XNamespace xns = "http://www.fruitauthority.fake"; 
XDocument xDoc = 
new XDocument(new XDeclaration("1.0", "utf-8", "yes"), 
new XElement(xns + "FruitBasket", 
new XElement(xns + "Fruit", 
new XElement(xns + "FruitName", "Banana"), 
new XElement(xns + "FruitColor", "Yellow")), 
new XElement(xns + "Fruit", 
new XElement(xns + "FruitName", "Apple"), 
new XElement(xns + "FruitColor", "Red")) 
)); 

0 Comment's

Comment Form

Submit Comment