Reputation: 348
I am creating a simple XML file here, and when I do I get this error about a non white space characters cannot be added to content.
In the constructor I passed a string to create the first node known as Root. This causes the non white space error in the code. Does anyone see the problem. This is C# on Visual Studio.
XDocument myDoc = new XDocument("Root");
myDoc.Add(
Enumerable.Range(0, 6).Select(i =>
new XElement("Entry",
new XAttribute("Address", "0123"),
new XAttribute("default", "0"),
new XElement("Descripion", "here is the description"),
new XElement("Data", "Data goes here ")
)));
myDoc.Save("foo.xml");
Upvotes: 3
Views: 6151
Reputation: 116108
Problem is at this line
XDocument myDoc = new XDocument("Root");
Change your code as:
XElement root = new XElement("root");
XDocument myDoc = new XDocument(root);
root.Add( Enumerable.Range...... );
myDoc.Save("foo.xml");
Upvotes: 10