简体   繁体   English

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

[英]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 在C#应用程序中加载XML文件时,我得到了

Name cannot begin with the '1' character, hexadecimal value 0x31. 名称不能以“1”字符开头,十六进制值0x31。 Line 2, position 2. 第2行,第2位。

The XML tag begins like this. XML标记就像这样开始。

<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? 我该如何解决这个问题?

You are supposed to change the tag name since the one you wrote violates the xml standard . 您应该更改标记名称,因为您编写的标记名称违反了xml标准 Just to remember the interesting portion of it here: 只是为了记住它的有趣部分:

XML Naming Rules XML命名规则

XML elements MUST follow these naming rules: XML 元素 必须遵循以下命名规则:

  • 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) 名称不能以字母xml(或XML或Xml等)开头
  • 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"/> 使用属性,即< Number value="1212041205115912"/>
  2. Add a prefix to the tag ie <_1212041205115912/> 为标记添加前缀,即<_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 . 当然你可以通过编写自己的格式解析器来保存你提出的结构,但是我可以说这将是一个非常糟糕的主意,因为将来有人可能会扩展格式并且不会很高兴看到看起来像这样的文件xml实际上不是,他/她可以为此生气 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. 此外,如果你想要你的自定义格式,使用更简单的东西,我的意思是:如果文本文件不是官方认可的格式,那么使用“<”和“>”来删除文本文件不会增加任何值,最好使用类似的东西。一个简单的纯文本文件。

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. 由于它是一个无效的xml文档,请在解析之前尝试清理它。 eg. 例如。 make a regex that replaces all < number> tags with < IMessedUp>number< /IMessedUp> and then parse it. 制作一个正则表达式,用<IMessedUp> number </ IMessedUp>替换所有<number>标签,然后解析它。

Sort of iffy way to do it, but I will solve your problem. 有点不确定的方式,但我会解决你的问题。

If you need to process this document, then stop thinking of it as XML, and cast aside any thoughts of using XML tools to process it. 如果您需要处理此文档,请不要将其视为XML,并抛弃使用XML工具处理它的任何想法。 You're dealing with a proprietary format and you will need to write your own tools to handle it. 您正在处理专有格式,您需要编写自己的工具来处理它。 If you want the benefits of using XML technology, you will have to redesign your documents so they are valid XML. 如果您希望使用XML技术的好处,则必须重新设计文档,使其成为有效的XML。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 名称不能以“1”字符开头,十六进制值0x31。 从xml文件中读取时 - Name cannot begin with the '1' character, hexadecimal value 0x31. while reading from an xml file 获取System.Xml.XmlException:名称不能以&#39;&#39;字符开头,十六进制值为0x20。 第42行,位置36 - Getting System.Xml.XmlException: Name cannot begin with the ' ' character, hexadecimal value 0x20. Line 42, position 36 名称不能以&#39;&#39;字符开头,十六进制值0x20 - Name cannot begin with the ' ' character, hexadecimal value 0x20 DataContractSerializer-名称不能以“。”开头 字符,十六进制值0x2E - DataContractSerializer - Name cannot begin with the '.' character, hexadecimal value 0x2E 名称不能以 '&lt;' 字符十六进制值 0x3c 开头 - Name cannot begin with the '<' character hexadecimal value 0x3c XDocument错误名称不能以&#39;&lt;&#39;字符开头,十六进制值0x3C - XDocument Error Name cannot begin with the '<' character, hexadecimal value 0x3C 使用xslt时,名称不能以&#39;=&#39;字符十六进制值0x3d开头 - Name cannot begin with the '=' character hexadecimal value 0x3d when use xslt xml.Linq:“名称不能以 &#39;?&#39; 开头字符,十六进制值 0x3F&quot; - xml.Linq: "Name cannot begin with the '?' character, hexadecimal value 0x3F" WCF服务参考 - 获取“XmlException:名称不能以&#39;&lt;&#39;字符开头,十六进制值0x3C”在客户端 - WCF Service Reference - Getting “XmlException: Name cannot begin with the '<' character, hexadecimal value 0x3C” on Client Side 将Firebase广告添加到Xamarin.Forms会导致:名称不能以&#39;$&#39;字符开头,十六进制值为0x24 - Adding Firebase Ads to Xamarin.Forms causes: Name cannot begin with the '$' character, hexadecimal value 0x24
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM