xmlnode = xmldoc.CreateElement(dRow.ItemArray.GetValue(0).ToString());
xmlroot.AppendChild(xmlnode);
xmlnode.InnerText = sub;
You can use:
string name = XmlConvert.EncodeName(dRow.ItemArray.GetValue(0).ToString());
to get a safe encoded name, then
xmlnode = xmldoc.CreateElement(name);
however; as Jon notes, this is highly unusual - and an encoded name is not pretty; for example a=b
becomes a_x003D_b
.
Look at the value of dRow.ItemArray.GetValue(0).ToString()
. It sounds like it isn't a valid element name, due to including an =
sign.
It's relatively rare to create an element with a name given dynamically from data. It's more common to specify the content of an element that way.
What exactly are you trying to achieve? What's in your row?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With