当我尝试从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);
}
}
您能帮我解决这个问题吗?我在Google上搜索了很多,但没有得到任何解决方案或解释,确切地指出了哪里出了错
答案 0 :(得分:1)
属性必须与标签名称之间用空格分隔:<GroupwareSubscriptionactionCode="04">
应该为<GroupwareSubscription actionCode="04">
。