[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Schema Extension and validation of an instance


schema extension base
Hi,

You need to use redefine to redefine the IPDRType. For that you need to 
have a schema with the same target namespace as the schema that defines 
IPDRType, so you should move the element declarations for the elements 
in the http://www.mySchema.com/ccf namespace in a separate schema file.
A working sample is below:

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

   <element name="transactionID" type="string"/>
   <element name="serviceID" type="string"/>
   <element name="serviceName" type="string"/>
   <element name="customerID" type="string"/>
   <element name="sessionID" type="string"/>
   <element name="timeZoneOffset" type="string"/>
</schema>

refedIPDR.xsd
=============
<?xml version = "1.0" encoding = "UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
   targetNamespace="http://www.ipdr.org/namespaces/IPDR"
   xmlns:ccf="http://www.mySchema.com/ccf"
   xmlns:ipdr="http://www.ipdr.org/namespaces/IPDR">

   <import namespace="http://www.mySchema.com/ccf"
     schemaLocation="ccf.xsd"/>

   <redefine schemaLocation="http://www.ipdr.org/public/IPDRDoc3.5.xsd">
     <complexType name="IPDRType">
       <complexContent>
         <extension base="ipdr:IPDRType">
           <sequence>
             <element ref="ccf:transactionID" minOccurs="0"/>
             <element ref="ccf:serviceID" minOccurs="0"/>
             <element ref="ccf:serviceName" minOccurs="0"/>
             <element ref="ccf:customerID" minOccurs="0"/>
             <element ref="ccf:sessionID" minOccurs="0"/>
             <element ref="ccf:timeZoneOffset" minOccurs="0"/>
           </sequence>
         </extension>
       </complexContent>
     </complexType>
   </redefine>

</schema>


valid instance

<?xml version="1.0"?>
<ipdr:IPDR xmlns="http://www.mySchema.com/ccf"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:ipdr="http://www.ipdr.org/namespaces/IPDR"
   xsi:schemaLocation="http://www.mySchema.com/ccf
   ccf.xsd http://www.ipdr.org/namespaces/IPDR redef.xsd">

   <ipdr:IPDRCreationTime>2001-05-31T13:20:00.561Z</ipdr:IPDRCreationTime>
   <ipdr:seqNum>1</ipdr:seqNum>
   <transactionID>1</transactionID>
   <serviceID>1</serviceID>
   <serviceName>New</serviceName>
   <customerID>Chris</customerID>
   <sessionID>1</sessionID>
   <timeZoneOffset>12</timeZoneOffset>
</ipdr:IPDR>


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


Christopher Foley wrote:
> Hi,
> 
> I want to extend an XML schema. An element exits in the base schema,
> which is defined to be of a certain complexType. I want to use this
> element but to extend its type. I do this with the files below but
> when I validate an instance of the extended schema , I get problems.
> 
> The base schema (IPDRDoc3.5.xsd) is as follows;
> =====================================
> 
> <schema xmlns="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://www.ipdr.org/namespaces/IPDR"
> xmlns:ipdr="http://www.ipdr.org/namespaces/IPDR" version="3.5">
>  <include schemaLocation="http://www.ipdr.org/public/IPDRTypes.xsd" />
> - <complexType name="IPDRType" final="restriction">
> - <annotation>
>  <documentation>This is the base type for the IPDR element. The
> service-specific schema can extend this by deriving from
> it.</documentation>
>  </annotation>
> - <sequence>
>  <element ref="ipdr:IPDRCreationTime" minOccurs="0" />
>  <element ref="ipdr:seqNum" minOccurs="0" />
>  </sequence>
>  </complexType>
> - <element name="IPDR" type="ipdr:IPDRType">
> - <annotation>
>  <documentation>An IPDR describes an event between a service consumer
> and a service element. Details of the event are contained within this
> record. All IPDR elements have a time indicating when the event
> occurred.</documentation>
>  </annotation>
>  </element>
>  </schema>
> 
> I want to use the IPDR element but extend the IPDRType complexType.
> 
> My Extending schema(filename -> ExtendedIPDR.xsd);
> =========================================
> 
> <?xml version = "1.0" encoding = "UTF-8"?>
> <schema xmlns = "http://www.w3.org/2001/XMLSchema"
>     targetNamespace = "http://www.mySchema.com/ccf"
>     xmlns:ccf = "http://www.mySchema.com/ccf
>     xmlns:ipdr = "http://www.ipdr.org/namespaces/IPDR">
> 
> <import namespace="http://www.ipdr.org/namespaces/IPDR"
> schemaLocation="http://www.ipdr.org/public/IPDRDoc3.5.xsd" />
> 
> 
> <complexType name="IPDRTypeExtended">
> <complexContent>
> <extension base="ipdr:IPDRType">
> <sequence>
>     <element name="ccf:transactionID" type="string" minOccurs="0"/>
>     <element name="ccf:serviceID" type="string" minOccurs="0" />
>     <element name="ccf:serviceName" type="string" minOccurs="0" />
>     <element name="ccf:customerID" type="string" minOccurs="0" />
>     <element name="ccf:sessionID" type="string" minOccurs="0" />
>     <element name="ccf:timeZoneOffset" type="string" minOccurs="0" />
> </sequence>
> </extension>
> </complexContent>
> </complexType>
> </schema>
> 
> Now I create an XML instance of my extended schema;
> ========================================
> 
> <?xml version="1.0"?>
> <ipdr:IPDR xmlns="http://www.mySchema.com/ccf "
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns:ipdr="http://www.ipdr.org/namespaces/IPDR"
>     xsi:schemaLocation="http://www.mySchema.com/ccf
> C:\myDownloads\myFiles\ExtendedIPDR.xsd">
> 
>     <ipdr:IPDRCreationTime>2001-0531T13:20:00.561Z</ipdr:IPDRCreationTime>
>     <ipdr:seqNum>1</ipdr:seqNum>
>     <transactionID>1</transactionID>
>     <serviceID>1</serviceID>
>     <serviceName>New</serviceName>
>     <customerID>Chris</customerID>
>     <sessionID>1</sessionID>
>     <timeZoneOffset>12</timeZoneOffset>
> </ipdr:IPDR>
> 
> Now my problem is when I validate the instance above against the
> extended schema(I am using Xselerator to do my validation). The error
> I'm getting is;
> ' The element 'transactionID' is used but not declared in the schema'.
> 
> But transactionID is defined and I even tried to prefix it with 'ccf'
> xmlns:ccf="http://www.mySchema.com/ccf" in the instance document and
> it still dosen't work.
> 
> Do I need to redefine the IPDR element itself to be of type 
> 'IPDRTypeExtended'??
> 
> Any help appreciated.
> 
> Best Regards,
> Chris.
> 
> -----------------------------------------------------------------
> 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>
> 

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.