Search code examples
c#xmlxmldocument

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


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?


Solution

  • IF you absolutely cant change it, eg. for some reason the format is already out in the wild and used by other systems/customers/whatever.

    Since it is an invalid xml document, try to clean it up before parsing it. eg. make a regex that replaces all < number> tags with < IMessedUp>number< /IMessedUp> and then parse it.

    Sort of iffy way to do it, but I will solve your problem.