Xml schema element with attribute and optional simple content?

Discussion in 'XML' started by Gazza, Dec 5, 2005.

  1. Gazza

    Gazza Guest

    I want to define an element type which has child elements which will
    have an attribute, but I want the presence of content for these child
    elements (which will be simple when present) to be optional. My type is
    defined as such

    <xsd:complexType name="DistanceStructure">
    <xsd:sequence>
    <xsd:element name="Value">
    <xsd:complexType>
    <xsd:simpleContent>
    <xsd:extension base="xsd:decimal">
    <xsd:attribute name="Comment" type="xsd:string"/>
    </xsd:extension>
    </xsd:simpleContent>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="Unit">
    <xsd:complexType>
    <xsd:simpleContent>
    <xsd:extension base="esdalcomm:DistanceUnitType">
    <xsd:attribute name="Comment" type="xsd:string"/>
    </xsd:extension>
    </xsd:simpleContent>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    This definition allows validation of the following when it appears in
    my instance document


    <StructureLength>
    <Value Comment="STRUCTURE LENGTH COMMENT">1.1</Value>
    <Unit Comment="STRUCTURE LENGTH COMMENT">metre</Unit>
    </StructureLength>

    But the following does not validate

    <StructureLength>
    <Value Comment="STRUCTURE LENGTH COMMENT"/>
    <Unit Comment="STRUCTURE LENGTH COMMENT"/>
    </StructureLength>



    I need both to be valid possiblilies in my instance document. What can
    I do?
    Gazza, Dec 5, 2005
    #1
    1. Advertising

  2. Gazza writes:

    > <xsd:element name="Value">
    > <xsd:complexType>
    > <xsd:simpleContent>
    > <xsd:extension base="xsd:decimal">
    > <xsd:attribute name="Comment" type="xsd:string"/>
    > </xsd:extension>
    > </xsd:simpleContent>
    > </xsd:complexType>
    > </xsd:element>


    > <Value Comment="STRUCTURE LENGTH COMMENT">1.1</Value>


    > <Value Comment="STRUCTURE LENGTH COMMENT"/>


    The empty string is not a valid xs:decimal, so you should define a union
    of the empty string (xs:string restricted to length 0, or xs:string
    restricted to an enumeration of only "") and xs:decimal, and use that
    instead of xs:decimal itself.

    ht
    --
    Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
    Half-time member of W3C Team
    2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
    Fax: (44) 131 650-4587, e-mail:
    URL: http://www.ltg.ed.ac.uk/~ht/
    [mail really from me _always_ has this .sig -- mail without it is forged spam]
    Henry S. Thompson, Dec 5, 2005
    #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. Markus
    Replies:
    1
    Views:
    1,528
    Markus
    Nov 23, 2005
  2. Andy Howden
    Replies:
    0
    Views:
    503
    Andy Howden
    Oct 20, 2003
  3. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,249
    Stanimir Stamenkov
    Apr 25, 2005
  4. tankbattle
    Replies:
    1
    Views:
    799
    George Bina
    Jul 21, 2006
  5. Jethrie-JDuprez in the news
    Replies:
    4
    Views:
    1,386
    Mayeul
    Apr 26, 2009
Loading...

Share This Page