Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


validate XML to XSD with MSXML

validate XML to XSD with MSXML

validate XML to XSD with MSXML

I'm trying to validate an XML against the XSD Schema.
At the point of adding the SchemaCache I get the error Incorrect definition for the root element in schema.

I may be completely wrong but I maybe missing a required namespace. I've having trouble understanding the MSXML model and I'm struggling to understand what I need here.

I'd be thankful for any help.


XML_FILE = "XML File Path" 
	XSD_FILE = "XSD File Path"
    Set xmlDoc = CreateObject("MSXML2.DOMDocument")
    xmlDoc.async = False
    xmlDoc.validateOnParse = False
    xmlDoc.resolveExternals = False

    xmlDoc.Load XML_FILE

    ' Open XSD file
    Set objXSD = CreateObject("MSXML2.DOMDocument")
    objXSD.async = False
    objXSD.Load XSD_FILE

    ' Populate schema cache
    Set objSchemaCache = CreateObject("MSXML2.XMLSchemaCache")

    objSchemaCache.Add "", objXSD
    ' XSD XML Bind
    Set xmlDoc.Schemas = objSchemaCache
    'Error visualization
    Set objErr = xmlDoc.Validate()
    If objErr.errorCode <> 0 Then
        sResult = "Error parser: " & objErr.errorCode & "; " & objErr.reason
        sResult = "No errors found"
    End If
	XSD_Validation = sResult 

The XML header example:


<ftc:FATCA_OECD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:oecd:ties:fatca:v1" xmlns:ftc="urn:oecd:ties:fatca:v1" xmlns:iso="urn:oecd:ties:isofatcatypes:v1" 
xmlns:sfa="urn:oecd:ties:stffatcatypes:v1" version="1.1"> 

RE: validate XML to XSD with MSXML

Try using

Set xmlDoc = CreateObject("MSXML2.DOMDocument.6.0")
Set objXSD = CreateObject("MSXML2.DOMDocument.6.0")
Set objSchemaCache = CreateObject("MSXML2.XMLSchemaCache.6.0")

although I'd probably not bother with objXSD at all, and simply add the schema directly:

objSchemaCache.Add "<your_schemas_namespace>", XSD_FILE

RE: validate XML to XSD with MSXML

Thanks for replying. I'm not sure I fully understand the concept of NameSpaces. As per the header in the OP would I need include multiple NameSpaces or just first?
Also without the objXSD Wharf anything would be the second parameter fir the .Add method?

RE: validate XML to XSD with MSXML

I'd imagine "urn:oecd:ties:fatca:v1"

RE: validate XML to XSD with MSXML

Thanks again, I'll try it when I'm back in the office.

RE: validate XML to XSD with MSXML

Many thanks, "urn:oecd:ties:fatca:v1" was indeed the namespace and specifying .6.0 ref has has given a fuller script error message:

FatcaXML_v1.1.xsd#/schewma/complexType[4][@name= 'CorrectableOrganisationParty_Type']/complexContent[1]/extention[1]Undefined
'{urn:oecd:ties:stffatcatypes:v1}OrganisationParty_Type' is used as a base type.

code: 80004005
source: msxml6.dll

Unfortunately I'm still at a loss as to the cause / resolution of this. Is this an error with the xml data (it has previously schema validated using xmlSpy), or is there still a problem with the code?

RE: validate XML to XSD with MSXML

I seem to have solved it, and it was thanks to strongm : "although I'd probably not bother with objXSD at all, and simply add the schema directly"

Lessons learned: listen to any advice given, in full.

RE: validate XML to XSD with MSXML

Difficult to say without the XSD and a (theoretically) valid XML example

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close