on XML catalogs and XSD

This should cover W3C XML Schema, Relax NG and DTD related problems.
mikeburke
Posts: 2

on XML catalogs and XSD

Wed Nov 17, 2004 4:44 pm

Hi, I'd really appreciate any help on integrating my existing XML schema into Oxygen's XML catalog, so I can use the nifty validation and content-assist features. I'm using Oxygen v5 as an eclipse plugin.

I have an XML document with the following header:

Code: Select all

<databean
      xmlns="http://www.xyz.com/databean"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.xyz.com/databean         
                         com/xyz/build/schema/databean.xsd">


I have an XSD document that defines the schema on the local file system under H:\workspace\src\com\xyz\build\schema\databean.xsd

The schema is correct, and the document validates correctly when performed manually.

My understanding of Oxygen is that I need to define my mapping from a schema reference to a physical location in an OASIS XML Catalog. I've created a catalog file as follows:

Code: Select all

<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer='public'>   
    <rewriteSystem
          systemIdStartString="com/xyz/build/schema"
          rewritePrefix="file:///H:/workspace/src/com/xyz/build/schema"/>
</catalog>


My understanding is that the SYSTEM ID passed to the catalog will be the trailing end of the schemaLocation attribute com/xyz/build/schema/databean.xsd (is my understanding correct?), and I am trying to tell the catalog to rewrite it as file:///H:/workspace/src/com/xyz/build/schema/databean.xsd.

This should then enable the XML parser to locate the schema, and therefore validate the document.

Needless to say, it doesn't work. Instead, I get an inline error saying 'cvc-elt.1: Cannot find the declaration of element 'databean'.

Can anyone spot the mistake I've made? Anyone with more experience able to point me in the right direction?

I have configured Eclipse to use the custom XML catalog, and have restarted Eclipse after making the changes.

thanks
mike
george
Site Admin
Posts: 2100

Wed Nov 17, 2004 6:02 pm

Hi Mark,

The problem is that the you have specified the schema using a relative location. The XML Catalog acts as an entity resolver for the parser and the parser will resolve the relative location before calling the catalog to resolve that. So instead of getting com/xyz/build/schema/databean.xsd the catalog will receive file:/pathToXML/com/xyz/build/schema/databean.xsd and that does not start with com/xyz/build/schema/databean.xsd so it will not bew rewritten.

The solution is to use an absolute location when you specify your schema in the instance document and eventually also make the schema available at that location http://xyz/com/schema/databean.xsd for instance so that tools that do not have XML Catalog support or an XML Catalog is not configured will be able to access the schema.

Hope that helps,
George
mikeburke
Posts: 2

Wed Nov 17, 2004 6:59 pm

Thanks George!

Your advice has done the trick. I always thought the schema location system we were using was slightly dodgy..

To summarise for others, the following works:

Code: Select all

<databean
      xmlns="http://www.xyz.com/databean"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.xyz.com/databean         
                          http://www.xyz.com/databean.xsd">


with an XML catalog entry looking like this:

Code: Select all

    <rewriteSystem
          systemIdStartString="http://www.xyz.com"
          rewritePrefix="file:///H:/workspace/src/com/xyz/schema"/>


This maps the parser's request for http://www.xyz.com/databean.xsd to H:\workspace\src\com\xyz\schema\databean.xsd

Thanks again and kind regards
Mike

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 0 guests