Name cannot begin with the '1' character, hexadecimal value 0x31. Line 2, position 2

aWebdesigner09 picture aWebdesigner09 · May 9, 2012 · Viewed 21.2k times · Source

While loading XML file in a C# application, I am getting

Name cannot begin with the '1' character, hexadecimal value 0x31. Line 2, position 2.

The XML tag begins like this.

<version="1.0" encoding="us-ascii" standalone="yes" />
<1212041205115912>

I am not supposed to change this tag at any cost.

How can I resolve this?

Answer

Felice Pollano picture Felice Pollano · May 9, 2012

You are supposed to change the tag name since the one you wrote violates the xml standard. Just to remember the interesting portion of it here:

XML Naming Rules

XML elements MUST follow these naming rules:

  • Names can contain letters, numbers, and other characters
  • Names cannot start with a number or punctuation character
  • Names cannot start with the letters xml (or XML, or Xml, etc)
  • Names cannot contain spaces

Any name can be used, no words are reserved.

as a suggestion to solve your problem mantaining the standard:

  1. Use an attribute, ie <Number value="1212041205115912"/>
  2. Add a prefix to the tag ie <_1212041205115912/>

Of course you can mantain the structure you propose by writing your own format parser, but I can state it would be a really bad idea, because in the future someone would probably extend the format and would not be happy to see that the file that seems xml it is actually not, and he/she can get angry for that. Furthermore, if you want your custom format, use something simpler, I mean: messing a text file with some '<' and '>' does not add any value if it is not an officially recognized format, it is better to use someting like a simple plain text file instead.