A
aaa
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.
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.