Can't validate W3C XML meta-schema

I

Ian Pilcher

Here's something rather interesting. I was working on a quick program
to validate XML documents against W3C schemas, and it occurred to me
that it might not be a bad idea to validate the schemas themselves. And
since I was going to validating schemas, and I had the meta-schema
handy...

Anyway, it doesn't appear to work. I'm attaching the code as
text/plain to avoid word wrap problems. Here is the output:

Meta-schema parsed
Meta-schema compiled
ERROR: 'UndeclaredPrefix: Cannot resolve 'xs:anyType' as a QName: the
prefix 'xs' is not declared.'

The stack trace confirms that the exception occurs at
schemaValidator.validate(metaSchemaSource);

A quick look at the metaschema shows that the 'xs' prefix certainly
appears to be declared.

BTW, the meta-schema and its associated DTDs can be found at
http://www.w3.org/2001/XMLSchema

Anyone see an obvious error in the code?

TIA
 
A

Andrew Thompson

Path: news-server.bigpond.net.au!lon-transit.news.telstra.net!lon-in.news.telstra.net!news.telstra.net!newsfeed.news2me.com!nx02.iad01.newshosting.com!newshosting.com!216.196.98.140.MISMATCH!border1.nntp.dca.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail
NNTP-Posting-Date: Mon, 22 Aug 2005 23:29:52 -0500
Date: Mon, 22 Aug 2005 23:29:49 -0500
From: Ian Pilcher <[email protected]>
User-Agent: Mozilla Thunderbird 1.0.6-1.1.fc4 (X11/20050720)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: comp.lang.java.programmer
Subject: Can't validate W3C XML meta-schema
Content-Type: multipart/mixed; boundary="------------080808020400070004080104"

<I usually get details wrong about 'attachments'>
My news client indicated your post was 84 lines, though
only aout 20 showed, and an icon like an 'attachment'
appeared beside your post. I cannot access it.

Please post content for this group in the body.
</I usually get details wrong about 'attachments'>

--
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"When you believe in things that you don't understand, you suffer.
Superstition ain't the way"
Stevie Wonder 'Superstitious'
 
I

Ian Pilcher

Andrew said:
<I usually get details wrong about 'attachments'>
My news client indicated your post was 84 lines, though
only aout 20 showed, and an icon like an 'attachment'
appeared beside your post. I cannot access it.

Please post content for this group in the body.
</I usually get details wrong about 'attachments'>

I'm afraid that my client is going to munge this terribly, be here goes:

package skitch.util;

import javax.xml.validation.*;
import javax.xml.parsers.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.Source;
import org.w3c.dom.*;
import java.net.*;
import java.io.*;

import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI;

/**
* A utility program to validate an XML file against a schema. (Since
* <tt>xmllint</tt> seems to be horribly broken.)
*/
public class CheckXML
{
public static void main(String[] args) throws Exception
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder parser = dbf.newDocumentBuilder();

URL url = CheckXML.class.getResource("../resources/XMLSchema.xsd");
File metaSchemaFile = new File(url.toURI());
Document metaSchemaDoc = parser.parse(metaSchemaFile);
Source metaSchemaSource = new DOMSource(metaSchemaDoc);
System.out.println("Meta-schema parsed");

SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
Schema metaSchema = sf.newSchema(metaSchemaSource);
System.out.println("Meta-schema compiled");

Validator schemaValidator = metaSchema.newValidator();
schemaValidator.validate(metaSchemaSource);
System.out.println("Meta-schema validated");
}
}
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top