Cannot add XML Schema to XML document for VBA Validation -


i trying validate xml document using schema provided online fca.

in xml file schema defined in headers 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 provide users tool validate xml generated our macro before load xml file fca reporting system.

so took code tomalak's answer in so: msxml vba: validating xml against xsd: “the '' namespace provided differs schema's targetnamespace.”

here modified version of code:

sub xsd_validation()     dim xmldoc msxml2.domdocument60     dim objschemacache new xmlschemacache60     dim objerr 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         debug.print "no errors found"     else         debug.print "error parser: " & objerr.errorcode & "; " & objerr.reason     end if end sub 

when run code below error:

pra%20export%20data%20jul%2017%202015.xml#/psd007-mortgageperformancesalesdata incorrect definition root element in schema.

what missing or doing wrong here?

after careful checking of answer provided tomalak on other question, resolved this.

in fact first argument of objschemacache.add should target namespace urn:fsa-gov- uk:mer:psd007:1 , second argument should the location of schema file http://www.fsa.gov.uk/mer/drg/psd007/v1-3/psd007-schema.xsd

so when 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, , tells me file not validate (which correct!)


Comments