Incorrect definition for root element in schema

I'm attempting to programatically validate an xml file using a schema(.xsd). My code is shown at the bottom. When I execute that code I get the above error at the "oxmlSchemaCache.Add" line. XSDDoc is a global variable defined as an MSXML2.DOMDocument which I successfully read as xml in another part of the program. The first part of the schema looks like the following. What is wrong?

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" elementFormDefault="qualified">



' Code
    Dim oxmlTempDoc As DOMDocument
    Dim oxmlSchemaCache As XMLSchemaCache

    Set oxmlTempDoc = New DOMDocument
    Set oxmlSchemaCache = New XMLSchemaCache

    ValidateXML = True

    oxmlTempDoc.async = False
    oxmlTempDoc.validateOnParse = False
   
    oxmlSchemaCache.Add "", XSDDoc
    Set oxmlTempDoc.schemas = oxmlSchemaCache
    oxmlTempDoc.Load gstrTempFileName
   
    If oxmlTempDoc.parseError <> 0 Then
        Err.Raise vbObjectError + 1, "PO Validation", oxmlTempDoc.parseError.reason

        ValidateXML = False
        Exit Function
    End If

    Set oxmlTempDoc = Nothing
    Set oxmlSchemaCache = Nothing
LVL 53
Martin LissOlder than dirtAsked:
Who is Participating?
 
Wayne BradneyIndependent ConsultantCommented:
MartinLiss,

Having now read the rest of the thread here, I think I see the problem.

I'm not a Microsoft-technology expert, but the problem is almost certainly that Microsoft's MSXML technology does not follow the W3C XML Schema standard (shocker!). Microsoft uses a schema language based upon the now defunct XML-Data specification, called Microsoft XML Data Reduced (XDR). See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmrefxmlschemareference.asp for details. Microsoft submitted this spec to the W3C back in 1998, but it was not adopted. Instead the W3C recommended XML Schema (http://www.w3.org/TR/xmlschema-0/) in May.

I'm not sure what MSXML3 is capable of validating, but I wouldn't be surprised if it didn't understand XML Schema content models.

BTW, Apache Xerces (http://xml.apache.org) is compliant with the current W3C XML Schema specification, as are several other parsers.

Regards,
WMB
0
 
slokCommented:
did you save the schema or the XML file in UTF-8 encoding?
try opening the files in Notepad and do a Save-As,
you should be able to see the option UTF-8, ANSI, Unicode etc..

just a thought
0
 
slokCommented:
or rather, if UTF-8 is the culprit, will ANSI works?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Martin LissOlder than dirtAuthor Commented:
When you refer to notepad, do you mean the "XML Notepad"? If so I don't have it. BTW, I didn't create the schema.
0
 
slokCommented:
no, just the normal NOTEPAD
0
 
Martin LissOlder than dirtAuthor Commented:
When I do Save As with my Notepad, it doesn't give me any other options except *.txt
0
 
slokCommented:
maybe we are on diferent OS.

I'm using win2k Professional.
0
 
Martin LissOlder than dirtAuthor Commented:
I'm using NT.

When I change UTF-8 to ANSI, I get a "System does not support the specified encoding". :(
0
 
slokCommented:
what if you remove    elementFormDefault="qualified"


think the namespace for XML Schema has changed quite a
fair bit. So, you might need to check what the parser
supports.


eg.

Xerces 1.3 only takes http://www.w3.org/2000/10/XMLSchema and
http://www.w3.org/2000/10/XMLSchema-instance 

Xerces 1.4 only takes http://www.w3.org/2001/XMLSchema and
http://www.w3.org/2001/XMLSchema-instance
0
 
Martin LissOlder than dirtAuthor Commented:
Removing elementFormDefault="qualified" makes no difference. I'm an xml novice; what is Xerces?
0
 
Martin LissOlder than dirtAuthor Commented:
I've increased the points since this obviously isn't easy. Do you code in VB? If so would you be willing to try to see if you could get my schema to work if I sent it to you.
I can be reached at martin.liss@icn.siemens.com
0
 
slokCommented:
Xerces is XML parsers. Similiar to what MSXML is.

More info. on Xerces on
http://xml.apache.org/

though, I would think you would be using MSXML.



0
 
Wayne BradneyIndependent ConsultantCommented:
MartinLiss,

Can you post the entire schema?

Regards,
WMB
0
 
Martin LissOlder than dirtAuthor Commented:
It's huge. If you email me at martin.liss@icn.siemens.com I will send it to you.
0
 
Martin LissOlder than dirtAuthor Commented:
It's huge. If you email me at martin.liss@icn.siemens.com I will send it to you.
0
 
Martin LissOlder than dirtAuthor Commented:
Changing to a different parser is not an option for me at this point. Are you saying that unless I can change the parser that I can't validate an xml file with my schema? I don't understand how that could be since XMLSpy can validate my xml file using my schema.
0
 
Wayne BradneyIndependent ConsultantCommented:
Martin,

XMLSpy probably doesn't use MSXML...

If I'm right about MSXML not supporting XML Schema, I'm afraid you're out of luck, and Microsoft has misled someone else into believing that their products are standards-compliant.

Regards,
WMB
0
 
Martin LissOlder than dirtAuthor Commented:
Changing to a different parser is not an option for me at this point. Are you saying that unless I can change the parser that I can't validate an xml file with my schema? I don't understand how that could be since XMLSpy can validate my xml file using my schema.
0
 
sdussingerCommented:
Martin:

One thing to check: what version of MSXML are you running? Are you running the default version which comes as part of Internet Explorer 5.x? If so, try updating to the newest version of MSXML. There are instructions on how to do so at:

http://www.bayes.co.uk/xml/index.xml?/xml/utils/instalmsxml.xml

HTH

--Steve
0
 
Martin LissOlder than dirtAuthor Commented:
Unfortunately you are correct, so I guess it's only right that I award you the points.

(I hope you don't mind the grade.)
0
 
CLT-ServicesCommented:
Hi All,

I have been having exactly the same problem (coding with Delphi and importing the TypeLib from MSXML5.DLL).

In fact I only subscribed to EE in order to be able to see this thread of answers to Martin Liss's question, but, just as Martin, changing to another parser was not an option. Browsing through MSDN samples I finally did find a working sample :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/XSD_HDI_Validate_schemaCacheJs.asp

Yet, comparing this code with my code, there didn't seem to be much difference.

I have been two days (not full time hopefully) without finding what it was and then light went on :
I was using the  '{373984C9-B845-449B-91E7-45AC83036ADE}' classID which stands in for XMLSchemaCache
It only works if you use the ClassID '{88D969E7-F192-11D4-A65F-0040963251E5}' (MSXML2.XMLSchemaCache.5.0)

It is a matter of version for your MSXML parser yet not, as I thought, of the version installed but rather of the version called !!!
0
 
AxterCommented:
>>It is a matter of version for your MSXML parser yet not, as I thought, of the version installed but rather of the version
>>called !!!
FYI:

Actually, it seems to be both.
MSXML2.XMLSchemaCache.5.0 is not available in MSXML4.DLL and below.

I'm using MSXML3.DLL, with XMLSchemaCache30, and it still fails.

I believe XMLSchemaCache40 should work, but you need MSXML4 or above (MSXML5.DLL).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.