How to validate a XML Schema

Siddhartha Singh

Usenet Archive
Joined
Aug 15, 2003
Messages
2
Reaction score
0
Hi,
If XML can be validated by either DTD or Schema and Schema itself is a XML. How can we validate a Schema ? Cheers, Siddhartha Singh
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Siddhartha said:
Hi,
If XML can be validated by either DTD or Schema and Schema itself is a XML. How can we validate a Schema ?

There is no complete XML Schema defining the XML schema however the schema processors usually validate a schema when you load it. For instance with MSXML 4 you can ask a schema to be validated when you add it to the schema cache. Consider the following schema with a typo (type mistyped as typ):

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

<xs:element name="GOD" typ="xs:string" />

</xs:schema>

When you load that schema with MSXML e.g. with

var schemaCollection = new ActiveXObject('Msxml2.XMLSchemaCache.4.0'); schemaCollection.validateOnLoad = true; try { schemaCollection.add('', 'test20030815Xsd.xml'); } catch (e) { alert(e.description); }

then an exception is caused an the alert shows that the attribute typ is not supported.
 

Siddhartha Singh

Usenet Archive
Joined
Aug 15, 2003
Messages
2
Reaction score
0
Hi Martin,
Thanks for your reply,
My question was regarding validation and not checking well formedness. The example you have shown is giving the syntax error and not the logical error in any schema. Cheers, Siddhartha

*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Siddhartha said:
Hi Martin,
Thanks for your reply,
My question was regarding validation and not checking well formedness. The example you have shown is giving the syntax error and not the logical error in any schema.

The example schema is well-formed:

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

<xs:element name="GOD" typ="xs:string" />

</xs:schema>

However it doesn't validate and I have posted how you can check that with MSXML 4.
 

Bob Foster

Usenet Archive
Joined
Aug 14, 2002
Messages
220
Reaction score
0
Several parsers divide validatation into two phases: load schema, and validate document. This allows multiple documents to be validated using the same schema without re-parsing it. It also allows you to "validate" the schema, by doing only the "load schema" part.

Alternatively, you can use a DTD or RELAX NG schema to validate an XML Schema, in the original sense of the word. (I don't believe it's possible to write a valid XML Schema for XML Schema, itself. If it is, the one in the standard certainly isn't it.)

The advantage of the former approach is it checks for errors that cannot be specified in a schema, like all referenced items are defined. The advantage of the latter approach is it can be used with "schema fragments" (schemas intended to be included or imported into other schemas but not used by themselves).

Bob Foster

"Siddhartha Singh" wrote:

Hi,
If XML can be validated by either DTD or Schema and Schema itself is a
XML.
How can we validate a Schema ?
Cheers,
Siddhartha Singh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,223
Members
248,131
Latest member
Tonypshaw1

Latest Threads

Top