Incorrect definition for the root element in XML schema

时间秒杀一切 提交于 2019-12-23 18:08:42

问题


There is a schema with the following boring root element:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

The schema is valid as far as I'm concerned, and Excel reads it no problem, for instance.

However, when I try to validate stuff agaist this schema using MSXML (v3 or v4 or v6) I get the subject error. (I create XMLSchemaCache and the error occurs when I add the loaded schema to it.)

From Google I learned that there is a conceptual problem with MS XML engines not conforming to W3 standards and that a different namespace definition must be used. However, I couldn't find neither that more correct definition nor any decent explanation of the problem. I could only find many posts without replies on forums.

Could anyone be so kind to explain the matter a bit deeper?

EDIT

For some reason, despite I cycled project references through versions 3, 4 and 6, version 3 was used all the time. A force switch to 4/6 solved it. So v3 is not able to parse the schema, others are fine. I believe that can be closed now.


回答1:


Ok, the problem was that I was using MSXML version 3 without realising it. Versions 4 and 6 work fine.

Sample code can be found here. And guys here were not too helpful.




回答2:


To suplement GSerg's auto answer (which was helpful btw) I'm adding some source information. First we get clear explanation in wiki:

Different versions of MSXML support slightly different sets of functionality. For example, while MSXML 3.0 supports only XDR schemas, it does not support XSD schemas. MSXML 4.0, MSXML 5.0, and MSXML 6.0 support XSD schemas. However, MSXML 6.0 does not support XDR schemas

Then we have What's New in MSXML msdn page, that confirms introducing xsd only in 4.0.

Finally as a general advice we have such an article on msdn: Why Version-Independent GUIDs and ProgIDs Were Removed. So I think we should just stick to 6.0.




回答3:


Interesting to know that MSXML version 6 still throws this error on XDR schema's, since support for it has been removed, as I learned here, more info here.




回答4:


I know this is an old question... but I just discovered in trying to solve this problem that the xmlns (namespace) attribute value being incorrect can also cause the error.

For example, the opening tag of the schema element should be like this:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

But, if you have a typo in the value, e.g. you are missing the colon:

<xsd:schema xmlns:xsd="http//www.w3.org/2001/XMLSchema">

you will get the "Incorrect definition for the root element in schema" error.



来源:https://stackoverflow.com/questions/2064026/incorrect-definition-for-the-root-element-in-xml-schema

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!