猿问

System.Xml.XmlException:“=”字符,十六进制值 0x3D,不能包含在名称中

当我尝试从 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);


        }

    }

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


慕森卡
浏览 1022回答 1
1回答

弑天下

属性必须与标签名称用空格分隔:&nbsp;<GroupwareSubscriptionactionCode="04">应该是<GroupwareSubscription actionCode="04">。
随时随地看视频慕课网APP
我要回答