Re: Question about combination of xsi:type and import

Hi Oliver,


> <?xml version="1.0" encoding="UTF-8"?>
> <tree:tree xmlns:tree="urn:tree"
> xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance">
>         <tree:leaf xsi:type="tree:extendedLeafType">
>                 <tree:name>eins</tree:name>
>                 <tree:info>Test</tree:info>
>         </tree:leaf>
> </tree:tree>
>
> Up until here there is no problem.

You'll need to give XML Spy an indication of where to locate your schema as
well. You do this with the xsi:schemaLocation attribute. So, the above example
would be:

<?xml version="1.0" encoding="UTF-8"?>
<tree:tree xmlns:tree="urn:tree"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:schemaLocation="urn:tree leafSchema.xsd">
        <tree:leaf xsi:type="tree:extendedLeafType">
                <tree:name>eins</tree:name>
                <tree:info>Test</tree:info>
        </tree:leaf>
</tree:tree>

> Now I want to do the following, but I don't know if it is possible. And if it
> is possible I don't know how
> to do it:
>
> The definition of the derived "extendedLeafType" should be in another
> namespace and therefor in another schema. Let's call the schema custom.xsd.
> The custom.xsd needs to import the tree.xsd schema.
> The tree.xsd should not know anything about the custom.xsd, because the
> custom.xsd is defined later (by some third party).
>
> But I want to write instance documents that use the derived type. So I tried
> the following:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <tree:tree xmlns:tree="urn:tree" xmlns:custom="urn:custom"
> xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance">
>         <tree:leaf xsi:type="custom:extendedLeafType">
>                 <tree:name>eins</tree:name>
>                 <custom:info>Test</tree:info>
>         </tree:leaf>
> </tree:tree>
>
> This does not work!
> I've tried to validate this with XML Spy and get the error: "Unknown type
> custom:extendedLeafType" (or something similiar).

Sure it will. You just have to add the xsi:schemaLocation attribute so your
instance will be:

<?xml version="1.0" encoding="UTF-8"?>
<tree:tree xmlns:tree="urn:tree" xmlns:custom="urn:custom"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:schemaLocation="urn:custom custom.xsd">
        <tree:leaf xsi:type="custom:extendedLeafType">
                <tree:name>eins</tree:name>
                <custom:info>Test</custom:info>
        </tree:leaf>
</tree:tree>

At the end you'll also find the two schemas.

Hope this helps
/Eddie

leafType.xsd
-------------
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="urn:tree"
xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" xmlns:tns="urn:tree"
elementFormDefault="qualified" attributeFormDefault="unqualified">
 <xsd:element name="tree" type="tns:branchType"/>
       <xsd:complexType name="leafType">
               <xsd:sequence>
                       <xsd:element name="name" type="xsd:string"/>
               </xsd:sequence>
       </xsd:complexType>
       <xsd:complexType name="branchType">
               <xsd:choice maxOccurs="unbounded">
                       <xsd:element name="leaf" type="tns:leafType"/>
                       <xsd:element name="branch" type="tns:branchType"/>
               </xsd:choice>
       </xsd:complexType>
</xsd:schema>

custom.xsd
-----------
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
elementFormDefault="qualified" xmlns:custom="urn:custom"
targetNamespace="urn:custom" xmlns:tns="urn:tree">
 <xsd:import namespace="urn:tree" schemaLocation="leafType.xsd"/>
       <xsd:complexType name="extendedLeafType">
               <xsd:complexContent>
                       <xsd:extension base="tns:leafType">
                               <xsd:sequence>
                                       <xsd:element name="info"
type="xsd:string"/>
                               </xsd:sequence>
                       </xsd:extension>
               </xsd:complexContent>
       </xsd:complexType>
</xsd:schema>

Received on Thursday, 17 May 2001 02:23:35 UTC