xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Ye" <eri...@locus.apache.org>
Subject Re: Schema Question
Date Wed, 08 Nov 2000 23:28:46 GMT
Good question to demonstrate powerfulness of schema:

With 04/07 schema spec, here is the syntax:

in your schema :
<schema ....xmlns:NS="your targetNamespace" targetNamespace ="your targetNamesapce">
    <complexType name="type1">
        <element name="type-1-element"/>

    <complexType name="type2" base="NS:type1" derivedBy="restriction">
        <element name="type-2-element"/>    

    <element name="myelement" type="NS:type1"/>

in your instance XML document use xsi:type attribute: 

by default myelement will have "type1"'s content model ,  if you do this:
<NS:myelement xmlns:xsi="...." xsi:type="type2"......

then myelement will have "type2"'s content model.

With the CR(10/24) version, the syntax is a little bit different for the schema part, here
it is:

    <complexType name="type1">
           <element name="type-1-element"/>

    <complexType name="type2" >
       <complexContent >
          <restriction base="type1>
              <element name="type-2-element"/>    

See, it is much more cumbersome than the 04/07 version, we should let the W3C working Group
know that schema syntax  is getting more and more diverted from simplicity and flexibility.

Eric Ye * IBM, JTC - Silicon Valley * ericye@locus.apache.org

  ----- Original Message ----- 
  From: Dane Foster 
  To: general@xml.apache.org 
  Sent: Wednesday, November 08, 2000 10:11 AM
  Subject: Schema Question

  I know that most of the post to this list deal with Xerces and Xalan so this may not be
the place to ask this question.  If it's not please let me know.  Anyway, my question is this,
in the current Schema specification (..2000/10/XMLSchema), how do I specify that if an element
contains a particular attribute it's children must be a specific element?
  Notes*: The myElement node's 'type' attribute can be one of two values "type1" or "type2".
 If the value is type1 then the root node(s) of the myElement sub-tree must be 'type-1-element'.
 If the value is type2 then the root node(s) of the myElement sub-tree must be 'type-2-element'.
  <!--Scenario one-->
  <myElement type="type1">
    <type-1-element>Element data goes here</type-1-element>
  <!--Scenario two-->
  <myElement type="type2">
    <type-2-element>Element data goes here</type-2-element>
  Dane Foster

View raw message