Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The '=' character, hexadecimal value 0x3D, cannot be included in a name

Tags:

c#

.net

xml

 xmlnode = xmldoc.CreateElement(dRow.ItemArray.GetValue(0).ToString());
 xmlroot.AppendChild(xmlnode);     
 xmlnode.InnerText = sub;  
like image 486
rachana Avatar asked Dec 28 '22 21:12

rachana


2 Answers

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.

like image 119
Marc Gravell Avatar answered Jan 23 '23 14:01

Marc Gravell


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?

like image 45
Jon Skeet Avatar answered Jan 23 '23 15:01

Jon Skeet