Add text to XDocument in CSharp
Description
The following code shows how to add text to XDocument.
Example
using System;//ww w.ja v a 2s. c o m
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
public class MainClass{
public static void Main(string[] args){
XDocument NewDoc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement("Root", "MyDoc"));
// Add some text.
NewDoc.Element("Root").Add(new XText("This is some text."));
Console.WriteLine(NewDoc);
}
}
The code above generates the following result.