I am trying to validate an XML document using the schema provided online by the FCA.
In the xml file the schema is defined in the headers like this:
<PSD007-MortgagePerformanceSalesData xmlns = "urn:fsa-gov-uk:MER:PSD007:1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:fsa-gov-uk:MER:PSD007:1
http://www.fsa.gov.uk/mer/drg/PSD007/v1-3/PSD007-Schema.xsd"
I want to provide the users with a tool to validate the xml generated by our macro before they load the xml file into the FCA Reporting system.
So I took the code from tomalak's answer in SO: MSXML VBA: Validating XML against XSD: “The '' namespace provided differs from the schema's targetNamespace.”
Here is my modified version of the code:
Sub XSD_Validation()
Dim xmlDoc As MSXML2.DOMDocument60
Dim objSchemaCache As New XMLSchemaCache60
Dim objErr As MSXML2.IXMLDOMParseError
objSchemaCache.Add "http://www.w3.org/2001/XMLSchema-instance" & Chr
(34) & " xsi:schemaLocation=" & Chr(34) & "urn:fsa-gov-uk:MER:PSD007:1
http://www.fsa.gov.uk/mer/drg/PSD007/v1-3/PSD007-Schema.xsd", LoadXmlFile
("C:\PRA Export Data Jul 17 2015.xml")
Set xmlDoc = LoadXmlFile("C:\PRA Export Data Jul 17 2015.xml")
Set xmlDoc.Schemas = objSchemaCache
Set objErr = xmlDoc.Validate()
If objErr.ErrorCode = 0 Then
Debug.Print "No errors found"
Else
Debug.Print "Error parser: " & objErr.ErrorCode & "; " & objErr.reason
End If
End Sub
When I run the code I get the below error:
PRA%20Export%20Data%20Jul%2017%202015.xml#/PSD007-MortgagePerformanceSalesData Incorrect definition for the root element in schema.
What am I missing or doing wrong here?