c# - 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);
}
}
你能帮我解决这个问题吗?我用谷歌搜索了很多,但没有得到任何解决方案或解释到底哪里出错了
解决方案
属性必须用空格与标签名称隔开: <GroupwareSubscriptionactionCode="04">
应该是<GroupwareSubscription actionCode="04">
.
推荐阅读
- reactjs - React 表显示完整数据而不是 20 个项目的页面
- jenkins - 使用带有 IP 地址而不是 URL 的 Github Webhook 是否有效?
- python - 当我对文件使用函数时出现错误消息
- elasticsearch - 弹性堆栈 - 无法运行 logstash
- javascript - 将数组转换为对象并计算重复的javascript
- javascript - js:移除或禁用之前添加的某个事件的事件监听器
- python - 气流:如何为运营商列表设置_dowstream
- ibm-mq - IBM MQ - 队列管理器/通道解决方案设计最佳实践
- facebook - Facebook Graph API - 签到帖子在页面上
- apache-flink - 重新启动任务管理器时 Apache Flink 丢失记录