【问题标题】:System.Xml.XmlException: The '=' character, hexadecimal value 0x3D, cannot be included in a name [closed]System.Xml.XmlException:“=”字符,十六进制值 0x3D,不能包含在名称中[关闭]
【发布时间】:2018-07-16 10:26:55
【问题描述】:

当我尝试从 stringReader 加载 XDocument 时,我收到此错误:

System.Xml.XmlException: The '=' character, hexadecimal value 0x3D, cannot be included in a name. Line 1, position 496.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
   at System.Xml.XmlTextReaderImpl.ParseElement()
   at System.Xml.XmlTextReaderImpl.ParseElementContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
   at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
   at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
   at System.Xml.Linq.XDocument.Load(TextReader textReader, LoadOptions options)
   at Rextester.Program.Main(String[] args)

下面是我尝试加载的一段代码:

 public class Program
    {
        public static void Main(string[] args)
        {
             String body = "<ContactBundleMaintainRequestMessage_sync><BasicMessageHeader><ID>b4cf2093e85242259f0b1b9122b75210</ID></BasicMessageHeader><Contact><UUID>4211feec-464c-4bd8-9490-f1041ed95504</UUID><LifeCycleStatusCode>2</LifeCycleStatusCode><GivenName>Carlo</GivenName><MiddleName /><FamilyName>DiBrigida</FamilyName><Relationship><RelationshipBusinessPartnerUUID>00163e11-a664-1ee8-85c3-74c6366e0886</RelationshipBusinessPartnerUUID><RoleCode>BUR027-2</RoleCode></Relationship><GroupwareSubscriptionactionCode="04"><EmployeeUUID>00163e11-a664-1ee8-85c3-74c6366e0886</EmployeeUUID></GroupwareSubscription></Contact></ContactBundleMaintainRequestMessage_sync>";
             StringReader read = new StringReader(body);
             XDocument xDoc = XDocument.Load(read);

        }
    }

您能帮我解决这个问题吗?我用谷歌搜索了很多,但没有得到任何解决方案或解释到底哪里出错了

【问题讨论】:

  • &lt;GroupwareSubscriptionactionCode=&gt; 不是 XML。所以你有一个有点像 XML 但不是的字符串。您不能指望 XML 工具可以使用它。由于我们不知道那里的意图是什么,您希望我们提供什么帮助?

标签: c# xml c#-4.0


【解决方案1】:

属性与标签名称之间必须用空格隔开:&lt;GroupwareSubscriptionactionCode="04"&gt; 应为 &lt;GroupwareSubscription actionCode="04"&gt;

【讨论】:

  • 不要回答错字问题,这些问题必须关闭。
  • 我发布的 Xml 是错误的。我现在已经更新了。请检查一下
  • 现在您在标签名称和属性之间缺少一个空格。我适当地编辑了答案。
  • @MKloster 什么空间?
  • @coders - SO 不是一个应该解决基本拼写错误的地方。如果您对 XML 有基本的了解,您应该明白 &lt;GroupwareSubscriptionactionCode=&gt;&lt;GroupwareSubscriptionactionCode="04"&gt; 都不是有效的 XML。如果您无法确定此处的错误,您需要自己熟悉 XML、元素和属性等的基础知识,我们也不是提供这些基础材料的地方。
猜你喜欢
  • 1970-01-01
  • 2021-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多