Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xml-dev] Sanity check please

From: George Cristian Bina <george@---------.--->
To: David Nedrow <dnedrow@---.--->
Date: 3/2/2006 4:55:00 AM
Hi David,

There are a number of problems here.
One problem is that the schema documents are not correct, you need to 
specify the namespace on an xs:import element, the schemaLocation is 
optional. There are also a number of other issues with your schemas like 
correctly referring to schema components in a specific namespace. A 
valid set of sample schemas is below.
A catalog then can resolve either the namespace or the schema location 
hint to an actual document (generally to a local document). However the 
catalog entries should be uri mappings or system mappings and not public 
as in your example. Ideally the parser should use the uri mappings for 
schemas but if it is used at SAX level for instance that will not be 
possible and schemas will be resolved only based on the location hint 
and using catalog system mappings.

basetypes.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns:ipbt="http://www.example.com/david/nedrow/ns/basetypes"
     targetNamespace="http://www.example.com/david/nedrow/ns/basetypes"
     elementFormDefault="qualified">
     <!--Declare a number of generic type equivalents-->
     <!-- string type -->
     <xs:complexType name="stringType" abstract="true">
         <xs:annotation>
             <xs:documentation>Character strings.</xs:documentation>
         </xs:annotation>
         <xs:simpleContent>
             <xs:extension base="xs:string"/>
         </xs:simpleContent>
     </xs:complexType>
</xs:schema>

datatypes.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
     targetNamespace="http://www.example.com/david/nedrow/ns/datatypes"
     xmlns:ipbt="http://www.example.com/david/nedrow/ns/basetypes"
     xmlns:ipdt="http://www.example.com/david/nedrow/ns/datatypes"
     elementFormDefault="qualified">
     <!--Generic descriptive text type -->
     <xs:import 
namespace="http://www.example.com/david/nedrow/ns/basetypes" 
schemaLocation="basetypes.xsd"/>
     <xs:complexType name="descriptionType" abstract="false">
         <xs:annotation>
             <xs:documentation>This is a generic descriptive text
                 entry.</xs:documentation>
         </xs:annotation>
         <xs:simpleContent>
             <xs:extension base="ipbt:stringType"/>
         </xs:simpleContent>
     </xs:complexType>
</xs:schema>

test.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
     targetNamespace="http://www.example.com/david/nedrow/ns/foo"
     xmlns:ipdt="http://www.example.com/david/nedrow/ns/datatypes"
     elementFormDefault="qualified">

     <xs:import 
namespace="http://www.example.com/david/nedrow/ns/datatypes" 
schemaLocation="datatypes.xsd"/>
     <xs:element name="ruleset">
         <xs:complexType>
             <xs:sequence>
                 <xs:element name="rule" minOccurs="1" 
maxOccurs="unbounded">
                     <xs:complexType>
                         <xs:sequence>
                             <xs:element name="name" 
type="ipdt:descriptionType"
                                 minOccurs="1" maxOccurs="1"/>
                             <xs:element name="desc" 
type="ipdt:descriptionType"
                                 minOccurs="1" maxOccurs="1"/>
                             <xs:element name="vdesc" 
type="ipdt:descriptionType"
                                 minOccurs="1" maxOccurs="1"/>
                         </xs:sequence>
                     </xs:complexType>
                 </xs:element>
             </xs:sequence>
         </xs:complexType>
     </xs:element>

</xs:schema>

In general you will not need a catalog file when you define your schemas 
unless you distribute them separately. Now assuming you make these 
schemas available at http://www.example.com/david/nedrow/test/ location 
then you can use a catalog like below in the same folder as the local 
copies of the schemas:

<?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.0/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
     <!-- This will resolve  for instance 
http://www.example.com/david/nedrow/test/datatypes.xsd to ./datatypes.xsd-->
     <rewriteSystem 
systemIdStartString="http://www.example.com/david/nedrow/test" 
rewritePrefix="."/>

</catalog>

and an XML instance document like

<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns="http://www.example.com/david/nedrow/ns/foo"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.example.com/david/nedrow/ns/foo 
http://www.example.com/david/nedrow/test/test.xsd">
     <rule>
         <name></name>
         <desc></desc>
         <vdesc></vdesc>
     </rule>
</ruleset>

will be able to find the local schemas and will be valid.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
www.---.com

David Nedrow wrote:
> I'm working on a new schema and have managed to get much of what I need 
> done, but I'm afraid that I'm doing some things incorrectly in an effort 
> to get it working. Sort of like adding closing parens to LISP code until 
> it works. ;)
> 
> Here's what I'm trying to accomplish....
> 
> A schema that references several other schemas in which are defined an 
> number of types. Everything to be pulled together by a catalog file.
> 
> I've included a heavily truncated and simplified version of what I'm 
> working with. My questions are as follows...
> 
> 1). Have I created an operable catalog file
> 2). Have I correctly built the <schema/> headers for the subsequent files?
> 3). If 1 & 2 are correct, why must I import the schemas in order to use 
> their defined elements? Shouldn't that be handled via my catalog file 
> and the <schema/> declarations?
> 
> I'd appreciate any input (good or bad) as to what I've provided below. I 
> have other questions, but their are predicated on the answers to my 
> questions above. ;)
> 
> -David
> 
> catalog.xml
> =========
> 
> <?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.0/catalog.dtd">
> <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" 
> prefer="public">
>     <public publicId="-//NEDRON//FOO Base Types V1.0//EN" 
> uri="basetypes.xsd"/>
>     <public publicId="-//NEDRON//FOO Data Types V1.0//EN" 
> uri="datatypes.xsd"/>
>     <public publicId="-//NEDRON//FOO Test V1.0//EN" uri="test.xsd"/>
> </catalog>
> 
> basetypes.xsd
> ===========
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>     xmlns:ipbt="-//NEDRON//FOO Base Types V1.0//EN"
>     elementFormDefault="qualified">
>     <!--Declare a number of generic type equivalents-->
>     <!-- string type -->
>     <xs:complexType name="stringType" abstract="true">
>         <xs:annotation>
>             <xs:documentation>Character strings.</xs:documentation>
>         </xs:annotation>
>         <xs:simpleContent>
>             <xs:extension base="xs:string"/>
>         </xs:simpleContent>
>     </xs:complexType>
> </xs:schema>
> 
> datatypes.xsd
> ===========
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>     targetNamespace="-//NEDRON//FOO Data Types V1.0//EN"
>     xmlns:ipbt="-//NEDRON//FOO Base Types V1.0//EN"
>     xmlns:ipdt="-//NEDRON//FOO Data Types V1.0//EN"
>     elementFormDefault="qualified">
>     <!--Generic descriptive text type -->
>     <xs:import schemaLocation="ipbt.xsd"/>
>     <xs:complexType name="descriptionType" abstract="true">
>         <xs:annotation>
>             <xs:documentation>This is a generic descriptive text
>             entry.</xs:documentation>
>         </xs:annotation>
>         <xs:simpleContent>
>             <xs:extension base="stringType"/>
>         </xs:simpleContent>
>     </xs:complexType>
> </xs:schema>
> 
> test.xsd
> ======
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>     targetNamespace="-//NEDRON//FOO Test V1.0//EN"
>     xmlns:ipft="-//NEDRON//FOO Filter Types V1.0//EN"
>     xmlns:ipdt="-//NEDRON//FOO Data Types V1.0//EN"
>     elementFormDefault="qualified">
>     <xs:import schemaLocation="basetypes.xsd"/>
>     <xs:import schemaLocation="datatypes.xsd"/>
>     <xs:element name="ruleset">
>         <xs:complexType>
>             <xs:sequence>
>                 <xs:element name="rule" minOccurs="1" 
> maxOccurs="unbounded">
>                     <xs:complexType>
>                         <xs:sequence>
>                             <xs:element name="name" type="descriptionType"
>                                 minOccurs="1" maxOccurs="1"/>
>                             <xs:element name="desc" type="descriptionType"
>                                 minOccurs="1" maxOccurs="1"/>
>                             <xs:element name="vdesc" type="descriptionType"
>                                 minOccurs="1" maxOccurs="1"/>
>                         </xs:sequence>
>                     </xs:complexType>
>                 </xs:element>
>             </xs:sequence>
>         </xs:complexType>
>     </xs:element>
> </xs:schema>
> 
> 
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
> 
> The list archives are at http://lists.xml.org/archives/xml-dev/
> 
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://www.oasis-open.org/mlmanage/index.php>
>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent