Search code examples
c#serializationxml-serialization

How to serialize object with numeric element name


public class UName
{
   [XmlElement("0.23")]
   public string Name1{get;set;}


}

when serialize above object then generated as below

  <UName><_x0030_.23>value</_x0030_.23></Uname>

I need as below as provided attribute number:

<UName><0.23>value</0.23></Uname>

Solution

  • What you want is not valid XML. Element names must start with a letter or underscore.

    See https://www.w3.org/TR/REC-xml/#NT-NameStartChar