The '=' character, hexadecimal value 0x3D, cannot be included in a name
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?
When you try to export a Microsoft catalog to XML, the resulting file cannot be imported, and you receive the following error message "The XML file path/filename contains an error at line. " "A Name contained an invalid character." If you validate the XML catalog by using Microsoft Visual Studio .NET you receive the following error message: "The '(' character, hexadecimal value 0x28, cannot begin a name. Line #, Position #" This problem occurs because the Commerce Server export was not encoding the following special characters:
The range 0x0021 – 0x002F includes ! “ # $ % & ‘ ( ) * + , - . /
The range 0x03A – 0x0040 includes : ; < = > ? @
The range 0x007B – 0x007E includes { | } ~
The range 0x005B – 0x005E [ \ ] ^**
The title is your answer. You can't use '=' in a name.
精彩评论