且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

名称不能以“1"字符开头,十六进制值 0x31.第 2 行,位置 2

更新时间:2022-10-21 19:05:58

如果 你绝对不能改变它,例如.出于某种原因,该格式已经被其他系统/客户/任何人使用.

既然是无效的xml文档,请在解析前尝试清理.例如.制作一个替换所有 < 的正则表达式number> 带有 < 的标签IMessedUp>数字 然后解析它.

有点不确定的方法,但我会解决你的问题.

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?

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.