Solved

Incorrect definition for root element in schema

Posted on 2001-09-17
22
2,580 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 47

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
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 
LVL 3

Expert Comment

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

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 47

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 47

Author Comment

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

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:Wayne Bradney
ID: 6494999
MartinLiss,

Can you post the entire schema?

Regards,
WMB
0
 
LVL 47

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:
Wayne Bradney 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 47

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 47

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:Wayne Bradney
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 47

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 47

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

729 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