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 开发者_StackOverflow社区the incoming xml in any way?
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.
精彩评论