0

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?

Community
  • 1
  • 1
Our Man in Bananas
  • 5,809
  • 21
  • 91
  • 148

1 Answers1

1

After some careful checking of the answer provided by tomalak on the other question, I resolved this.

In fact the first argument of objSchemaCache.Add should be the target namespace which is urn:fsa-gov- uk:MER:PSD007:1 and the second argument should be the location of the schema file which is http://www.fsa.gov.uk/mer/drg/PSD007/v1-3/PSD007-Schema.xsd

So when I used

    objSchemaCache.Add "urn:fsa-gov-
uk:MER:PSD007:1", "http://www.fsa.gov.uk/mer/drg/PSD007/v1-3/PSD007-Schema.xsd"

it works, and now tells me that the file does not validate (which is correct!)

Our Man in Bananas
  • 5,809
  • 21
  • 91
  • 148