如果遇到两次,XDocument 无法消化标头中的 url
我正在使用来自政府网关的 xml 响应,该网关在其根节点中包含两次 url(首先是 xsi:schemaLocation="http://www.govtalk.gov.uk/CM/envelope" 以及 xmlns="http: //www.govtalk.gov.uk/CM/envelope")
仅当我从节点中取出第二个(xmlns 一个)时,XDocument 才会解析此内容。
有什么方法可以让我准备 XDocument 来消化这个重复的 URL,而不必以任何方式操作传入的 xml?
I am consuming an xml response from a government gateway which contains a url in its root node twice (being firstly xsi:schemaLocation="http://www.govtalk.gov.uk/CM/envelope" and also xmlns="http://www.govtalk.gov.uk/CM/envelope")
XDocument will only parse this if I pull out the second one (the xmlns one) from the node.
Is there some way I can prepare XDocument to digest this repeated URL without having to manipulate the incoming xml in any way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题不在于存在重复的 URL,而在于您从网关接收的 XML 未正确使用 xsi:schemaLocation 属性。该属性应包含成对的空格分隔的 URI,其中每对都向 XML 处理器提供有关在何处查找与命名空间对应的 XML 模式的提示。请参阅 http://www.w3.org/TR/xmlschema-0/#schemaLocation 有关 schemaLocation 的说明。
如果您必须删除某些内容,请将其设为 xsi:schemaLocation 属性。
如果您要根据架构验证收到的 XML,则必须采取措施提供架构文档的位置,例如填充 XmlSchemaSet 并将其传递到 验证扩展方法。
The problem is not that there is a repeated URL, but that the XML you are receiving from the gateway is not using the xsi:schemaLocation attribute correctly. The attribute should contain pairs of whitespace separated URIs, where each pair gives the XML processor a hint about where to find the XML schema corresponding to a namespace. See http://www.w3.org/TR/xmlschema-0/#schemaLocation for an explanation of schemaLocation.
If you have to strip out something, make it the xsi:schemaLocation attribute.
If you are validating the received XML against a schema then you will have to take steps to provide the location of the schema document, for instance populating an XmlSchemaSet and passing it to the Validate extension method.