Can't validate W3C XML meta-schema

Discussion in 'Java' started by Ian Pilcher, Aug 23, 2005.

  1. Ian Pilcher

    Ian Pilcher Guest

    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

    --
    ========================================================================
    Ian Pilcher
    ========================================================================
     
    Ian Pilcher, Aug 23, 2005
    #1
    1. Advertising

  2. On Mon, 22 Aug 2005 23:29:49 -0500, Ian Pilcher wrote:

    > 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 <>
    > 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'
     
    Andrew Thompson, Aug 23, 2005
    #2
    1. Advertising

  3. Ian Pilcher

    Ian Pilcher Guest

    Andrew Thompson wrote:
    >
    > <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");
    }
    }

    --
    ========================================================================
    Ian Pilcher
    ========================================================================
     
    Ian Pilcher, Aug 23, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,541
    Markus
    Nov 23, 2005
  2. Frank
    Replies:
    9
    Views:
    1,570
    David Dorward
    May 3, 2004
  3. Steve Jorgensen
    Replies:
    0
    Views:
    560
    Steve Jorgensen
    Aug 9, 2005
  4. Ian Pilcher

    W3C meta-schema - useless?

    Ian Pilcher, Aug 31, 2005, in forum: XML
    Replies:
    5
    Views:
    561
    Henry S. Thompson
    Sep 2, 2005
  5. Replies:
    1
    Views:
    373
Loading...

Share This Page