I’m trying to solve one programming mystery (to me). I have searched with Google but I have found nothing about the use of semicolon in the AttributeName property of XmlAttribute. I’m working with an application that serializes an object. When this object is serialized all the attributes has the same value as a postfix.
For example:
[XmlType(TypeName = "Foo", Namespace = Declarations.SchemaVersion), XmlRoot, Serializable]
public class Foo
{
private string _Name;
[XmlAttribute(AttributeName = "Name;", Form = XmlSchemaForm.Unqualified, DataType = "string", Namespace = Declarations.SchemaVersion)]
public string Name
{
get
{
return this._Name;
}
set
{
this._Name = value;
}
}
}
Get serialize as:
<Foo Name_x003B_="John" />
My question is, where does this x003B came from (I have searched the code for a literal “x003B” but found nothing {the above is just an example, I’m working with a big code base}). Where can I change it? What is the purpose of the semicolon at the end of the AttributeName? Thanks!
The XmlSerializer encodes characters such as semicolon by placing it in underscores with the hex value of the character inside so Name; becomes Name_0x003B_. If you put a question mark in there it would be Name_0x003F_.