locating schemas with catalog w/out instance schemaLocations

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

locating schemas with catalog w/out instance schemaLocations

Sun Mar 11, 2007 8:59 am

Is the following scenario possible with oXygen? (I'm using the Eclipse version.)

1. I have a schema that starts like:

Code: Select all

<xs:schema xmlns="http://my.tld/something" targetNamespace="http://my.tld/something" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0" xml:lang="EN">


2. I have an instance document that starts like:

Code: Select all

<something xmlns="http://my.tld/something">


3. I have a catalog that starts like:

Code: Select all

<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
  <uri name="http://my.tld/something" uri="schemas/something.xsd"/>


4. oXygen sees the namespace declaration in the instance document, looks in the catalog and finds out the location of the local copy of the schema for that namespace, and uses it to validate the instance document.

Note that I do not have the xsi:schemaLocation attributes in the instance document. I strongly prefer to omit those, and have validation triggered in the way I have described.

If this is not possible with oXygen out of the box, would it be possible for me to make oXygen use a different parser implementation that would be able to do this? Norm Walsh has a new version of the xml resolver code in the works, and I've been able to get it to work in this fashion. The only additional requirement is to "decorate" the catalog like this:

Code: Select all

<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" xmlns:r="http://www.rddl.org/" prefer="system">
  <uri r:nature="http://www.w3.org/2001/XMLSchema"
    r:purpose="http://www.rddl.org/purposes#schema-validation" name="http://my.tld/something" uri="schemas/something.xsd"/>


I like that a lot better than having to pollute my instance documents with all that xsi:schemaLocation stuff that is just intended to "fake out" the parser.

Would oXygen pay attention to the settings of these properties:

Code: Select all

javax.xml.parsers.SAXParserFactory
javax.xml.stream.XMLInputFactory
javax.xml.parsers.DocumentBuilderFactory


? If so, it might be possible to swap in the new xml resolver stuff and get this kind of validation to work. Or is there a simpler way to accomplish this without such tweaking?

Thanks!
george
Site Admin
Posts: 2100

Mon Mar 12, 2007 1:50 pm

Hi,

What you can do currently in oXygen to get a schema associated with a document without specifying that association in the document is to use the Defautl Schema Association options, see in Eclipse Window->Preferences -- oXygen -- Editor -- Default Schema Association page. There you can specify based on the root element local name and namespace and/or based on the file name a schema file to be used for validation and content completion on the documents that match.

oXygen uses the Xerces J parser at SAX level and SAX cannot distinguish between a schema, a DTD or external entities when it invokes a resolver. Therefore it is not possible to use the URI catalog entries to resolve a schema based only on its namespace. In the future there are plans to allow for that possibility - however as explained above most of this use case is covered by the default schema association options.

Best Regards,
George
George Cristian Bina
Marty3009
Posts: 1

Re: locating schemas with catalog w/out instance schemaLocations

Fri Oct 08, 2010 7:15 pm

Hi,
I have the same problem (I don't want any ugly schemaLocation attributes in my XML documents). To avoid the schemaLocation attribute, I also tried an XML catalog (with URI mappings).

It works partially, but I found an inconsistent resolving behaviour which I think is not correct. (before I continue: I am using Oxygen version 12.0., therefore I could not follow your hint with the default schema association preferences, I could not find this preference in Version 12.0).

I have two little schemas, schema_a.xsd, schema_b.xsd.

schema_a.xsd

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
  elementFormDefault="qualified" 
  targetNamespace="http://a" xmlns="http://a"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:element name="root">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="test" type="xsd:boolean"/>
        <xsd:any maxOccurs="unbounded" minOccurs="0" namespace="##any" processContents="strict"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>


schema_b.xsd

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
  elementFormDefault="qualified"
  targetNamespace="http://b" xmlns="http://b"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 
  <xsd:element name="number" type="xsd:integer"/>
</xsd:schema>


The XML catalog:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog PUBLIC "-//OASIS//DTD XML Catalogs V1.1//EN" "http://www.oasis-open.org/committees/entity/release/1.1/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
    <uri name="http://a" uri="file:/C:/test/schema_a.xsd"/>
    <uri name="http://b" uri="file:/C:/test/schema_b.xsd"/>
</catalog>


The instance file:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<a:root xmlns:a="http://a" xmlns:b="http://b"> 
    <a:test>true</a:test>
    <b:number>1</b:number>
</a:root>


Strangely enough, the schema_a.xsd got resolved by the catalog mapping, where schema_b.xsd didn't get resolved. I get the error:
"cvc-complex-type.2.4.c: The matching wildcard is strict,
but no declaration can be found for element 'b:number'.

(Of course I also tried using an explicit schemaLocation, if I do so, everything validates as it should).

When using the Eclipse XML Editor and the Eclipse XML catalog resolver (WTP plugin), the above example works as it should.

Is there anything I can do to get this configuration working with Oxygen, too? I want to make the switch from Eclipse to Oxygen, but this hurdle is really startling me.

Thanks for your help,
Regards,
Martin
george
Site Admin
Posts: 2100

Re: locating schemas with catalog w/out instance schemaLocations

Mon Oct 11, 2010 3:42 pm

To make this work you need to add in schema_a.xsd

<xsd:import namespace="http://b"/>

and make sure you enable the
"Process namespaces through uri mappings for XML Schema" in Options->Preferences -- XML / XML Catalog in oXygen standalone. In Eclipse the location is Eclipse->Preferences -- oXygen -- XML -- XML Catalog.

Best Regards,
George
George Cristian Bina

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 1 guest