Abstract and Schema

Discussion in 'XML' started by Jason Cavett, Jan 17, 2008.

  1. Jason Cavett

    Jason Cavett Guest

    I'm attempting to create a schema where I have an abstract model from
    which all other nodes "extend" the model (so I don't need to retype
    the same information repeatedly). Something like this...

    <xs:complexType name="DataModel" abstract="true">
    <xs:complexContent>
    <xs:extension base="DataModel">
    <xs:sequence>
    <xs:element name="data">
    <xs:complexType>
    <xs:sequence>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="children">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="Notes" type="NotesModel"
    minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:extension>
    </xs:complexContent>
    </xs:complexType>

    However, what I do not understand is - when I create the other
    elements that rely on DataModel...how do I continue to expand the
    existing nodes. (For example, I want to add additional elements to
    the "children" node.)


    Thanks
     
    Jason Cavett, Jan 17, 2008
    #1
    1. Advertising

  2. Jason Cavett wrote:
    > However, what I do not understand is - when I create the other
    > elements that rely on DataModel...how do I continue to expand the
    > existing nodes. (For example, I want to add additional elements to
    > the "children" node.)


    You can't override existing element definitions. <children> will always
    have the contents it originally had, unless you replace the basic schema.

    What you can do is define a type for the element, define new types which
    extend that type, and define new elements which implement the extended
    type. Then, if you say that what's expected at that point in the
    document is an instance of the base type, elements having any of the
    extended types will also be accepted.

    See, for example, XML Schema Part 0's example of deriving types by
    extension:
    http://www.w3.org/TR/xmlschema-0/#DerivExt
    and related sections.

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Jan 17, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DaKoadMunky
    Replies:
    4
    Views:
    572
    Lee Weiner
    Apr 20, 2004
  2. Sameer
    Replies:
    4
    Views:
    632
    Roedy Green
    Aug 31, 2005
  3. Markus
    Replies:
    1
    Views:
    1,663
    Markus
    Nov 23, 2005
  4. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,327
    Stanimir Stamenkov
    Apr 25, 2005
  5. Replies:
    4
    Views:
    864
    Rolf Magnus
    May 17, 2006
Loading...

Share This Page