Hi,
> 1. Cannot set a value on node type: Element.
Use the InnerText property instead.
> 2. Specified argument was out of the range of valid values.
On which line does this error happen?
> 3. This document already has a DocumentElement node.
Looks like you are trying to create multiple top-level nodes, which is
prohibited. I can't see from your code where you append the created nodes to
xDoc - again, can you specify the exact line where this error happens?
--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx
"aaa" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Can someone show me a snippet that creates a very simple XML doc with
> either
> a root and chilc nodes or root child nodes, and attributes.
>
> I have looked all around and every example I try I get an error of either:
>
> 1. Cannot set a value on node type: Element.
> 2. Specified argument was out of the range of valid values.
> 3. This document already has a DocumentElement node.
>
> Here is the code i've been working with:
> XmlDocument xDoc= new XmlDocument();
> XmlDeclaration xmlDecl = xDoc.CreateXmlDeclaration("1.0", "utf-8",
> null);
> xDoc.AppendChild(xmlDecl);
> XmlAttribute nameAttr;
> int f = 3;
>
> for (int i = 0; i <= f; i ++)
> {
> XmlNode topNode = xDoc.CreateNode(XmlNodeType.Element, "blah", null);
>
> nameAttr = xDoc.CreateAttribute(null, "a", null);
> nameAttr.Value = "123";
> topNode.Attributes.Append(nameAttr);
> nameAttr = xDoc.CreateAttribute(null, "b", null);
> nameAttr.Value = "123";
> topNode.Attributes.Append(nameAttr);
> nameAttr = xDoc.CreateAttribute(null, "c", null);
> nameAttr.Value = "123";
> topNode.Attributes.Append(nameAttr);
> nameAttr = xDoc.CreateAttribute(null, "d", null);
> nameAttr.Value = "123";
> topNode.Attributes.Append(nameAttr);
> nameAttr = xDoc.CreateAttribute(null, "e", null);
> nameAttr.Value = "123";
> topNode.Attributes.Append(nameAttr);
> }
>
> I have tried all different node types and no luck. thnx.
>
>
>