xs:include change base type

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

xs:include change base type

Karl Stubsjoen
I would like to extend an xs:complexType, and change one of its
attributes from a type xs:NCName to xs:simpleType, with the same base
type mind you.  So something like this:


<xs:complextType name="myComplexType">
  <xs:sequence>...</xs:sequence>
  <xs:attribute name="name" type="xs:NCNAME"/>
</xs:complexType>


Then...

<xs:complexType name="myNewComplexType">
<xs:complexContent>
  <xs:extension base="myComplextType">
     <xs:attribute name="name" type="some_simple_type"/>
  </xs:extension>
</xs:complexContent>
</xsl:complexType>


Is this possible?  I've tried but having no luck.

--
Karl Stubsjoen
MeetScoresOnline.com
(602) 845-0006

Reply | Threaded
Open this post in threaded view
|

Re: xs:include change base type

Mukul Gandhi
Hi Karl,
   Your subject line says xs:include, but the use case doesn't mention
xs:include. I'm going by the details within your mail text.

Below is the solution I can propose.

The problem with using an XSD 1.0 style complexType extension and
achieving your requirement is, that "name" attribute would be reported
as duplicate declarations during an extension definition.

Here's an XSD 1.1 solution using an <assert> element,

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

     <xs:element name="A" type="myNewComplexType"/>
       
     <xs:complexType name="myNewComplexType">
         <xs:complexContent>
              <xs:extension base="myComplexType">
                   <xs:assert test="string-length(@name) eq 5"/>
              </xs:extension>
         </xs:complexContent>
     </xs:complexType>
       
 <!--<xs:simpleType name="some_simple_type">
           <xs:restriction base="xs:NCName">
                 <xs:length value="5"/>
           </xs:restriction>
      </xs:simpleType> -->
       
    <xs:complexType name="myComplexType">
         <xs:sequence>
             <xs:element name="x" type="xs:string"/>
         </xs:sequence>
         <xs:attribute name="name" type="xs:NCName"/>
     </xs:complexType>
       
</xs:schema>

The <assert> in this example simulates the commented simpleType shown
in my example.

Here's a valid XML instance document for the above schema:

<A name="x1234">
  <x>hello</x>
</A>

Here's an invalid XML instance document for the above schema:

<A name="x12345">
   <x>hello</x>
</A>

There may be other ways of thinking about the solution to this use
case. But this one came to my mind quickly.

On Fri, Jun 7, 2013 at 3:03 AM, Karl Stubsjoen <[hidden email]> wrote:

> I would like to extend an xs:complexType, and change one of its
> attributes from a type xs:NCName to xs:simpleType, with the same base
> type mind you.  So something like this:
>
>
> <xs:complextType name="myComplexType">
>   <xs:sequence>...</xs:sequence>
>   <xs:attribute name="name" type="xs:NCNAME"/>
> </xs:complexType>
>
>
> Then...
>
> <xs:complexType name="myNewComplexType">
> <xs:complexContent>
>   <xs:extension base="myComplextType">
>      <xs:attribute name="name" type="some_simple_type"/>
>   </xs:extension>
> </xs:complexContent>
> </xsl:complexType>
>
>
> Is this possible?  I've tried but having no luck.
>
> --
> Karl Stubsjoen
> MeetScoresOnline.com
> (602) 845-0006



--
Regards,
Mukul Gandhi