xml schema to specify element type based on attribute value?

Discussion in 'XML' started by James, Jul 18, 2007.

  1. James

    James Guest

    Hello,

    I'm trying to create a schema for the following document..

    <Foo>
    <Content type="html">
    ... valid xhtml goes here ...
    </Content>
    <Content type="plain">
    ... xs:string value goes here ...
    </Content>
    </Foo>

    So, basically I need to specify that the type of the Content element
    will be a complex type with a sequence of xs:any when the value of the
    type attribute on that element is "html" or it's an simple type of
    xs:string when the value of the type attribute is "plain"..

    Is this possible with xsd?

    Thanks,

    -jr
     
    James, Jul 18, 2007
    #1
    1. Advertisements

  2. James wrote:
    > Is this possible with xsd?


    Better solution with XSD is <html-content> versus <plain-content>.


    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Jul 18, 2007
    #2
    1. Advertisements

  3. >> Is this possible with xsd?
    > Better solution with XSD is <html-content> versus <plain-content>.


    Should have added: You could also do things with instance-document type
    directives (http://www.w3.org/TR/xmlschema11-1/#xsi_type). But I've
    rarely seen that used well...

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
     
    Joe Kesselman, Jul 28, 2007
    #3
    1. Advertisements

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.