Solved

Incorrect definition for root element in schema

Posted on 2001-09-17
22
2,525 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:Martin Liss
  • 10
  • 6
  • 3
  • +3
22 Comments
 
LVL 3

Expert Comment

by:slok
ID: 6488880
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
 
LVL 3

Expert Comment

by:slok
ID: 6488882
or rather, if UTF-8 is the culprit, will ANSI works?
0
 
LVL 46

Author Comment

by:Martin Liss
ID: 6488886
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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
LVL 3

Expert Comment

by:slok
ID: 6488888
no, just the normal NOTEPAD
0
 
LVL 46

Author Comment

by:Martin Liss
ID: 6488986
When I do Save As with my Notepad, it doesn't give me any other options except *.txt
0
 
LVL 3

Expert Comment

by:slok
ID: 6489092
maybe we are on diferent OS.

I'm using win2k Professional.
0
 
LVL 46

Author Comment

by:Martin Liss
ID: 6489114
I'm using NT.

When I change UTF-8 to ANSI, I get a "System does not support the specified encoding". :(
0
 
LVL 3

Expert Comment

by:slok
ID: 6489162
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
 
LVL 46

Author Comment

by:Martin Liss
ID: 6493593
Removing elementFormDefault="qualified" makes no difference. I'm an xml novice; what is Xerces?
0
 
LVL 46

Author Comment

by:Martin Liss
ID: 6494031
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
 
LVL 3

Expert Comment

by:slok
ID: 6494332
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
 
LVL 6

Expert Comment

by:wbradney
ID: 6494999
MartinLiss,

Can you post the entire schema?

Regards,
WMB
0
 
LVL 46

Author Comment

by:Martin Liss
ID: 6495013
It's huge. If you email me at martin.liss@icn.siemens.com I will send it to you.
0
 
LVL 6

Accepted Solution

by:
wbradney earned 150 total points
ID: 6495040
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
 
LVL 46

Author Comment

by:Martin Liss
ID: 6495045
It's huge. If you email me at martin.liss@icn.siemens.com I will send it to you.
0
 
LVL 46

Author Comment

by:Martin Liss
ID: 6495073
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
 
LVL 6

Expert Comment

by:wbradney
ID: 6495133
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
 
LVL 46

Author Comment

by:Martin Liss
ID: 6495162
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
 
LVL 4

Expert Comment

by:sdussinger
ID: 6498039
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
 
LVL 46

Author Comment

by:Martin Liss
ID: 6543467
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
 

Expert Comment

by:CLT-Services
ID: 11540657
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
 
LVL 30

Expert Comment

by:Axter
ID: 12885115
>>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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question