How to define an empty or type-safe element in XSD

Discussion in 'XML' started by SW, Oct 7, 2003.

  1. SW

    SW Guest

    Hello,

    Can anyone show me how to define in an XSD schema that an element in
    an XML document can either contain no text, or if it does contain text
    that the text has to be of a specific type.

    For example, I would like both the following to be valid, where any
    text present should equate to an integer, but an empty element is also
    valid:

    <mytest></mytest>

    or

    <mytest>123</mytest>

    Many thanks in advance
    SW, Oct 7, 2003
    #1
    1. Advertising

  2. In article <>,
    SW <> wrote:

    % For example, I would like both the following to be valid, where any
    % text present should equate to an integer, but an empty element is also
    % valid:
    %
    % <mytest></mytest>
    %
    % or
    %
    % <mytest>123</mytest>

    I was waiting to see if someone who's more of a schema person than me
    answered, but I'll stoke the fire by suggesting you use a union.

    <xs:element name='mytest'>
    <xs:simpleType>
    <xs:union>
    <xs:simpleType>
    <xs:restriction base="xs:integer"/>
    </xs:simpleType>
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:length value="0"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:union>
    </xs:simpleType>
    </xs:element>
    --

    Patrick TJ McPhee
    East York Canada
    Patrick TJ McPhee, Oct 11, 2003
    #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. gabriel
    Replies:
    1
    Views:
    1,353
    Nobody
    Jun 25, 2003
  2. John

    empty/non-empty element

    John, Jul 15, 2003, in forum: XML
    Replies:
    1
    Views:
    1,013
    Klaus Johannes Rusch
    Jul 16, 2003
  3. Matthet
    Replies:
    2
    Views:
    662
    Matthet
    Sep 24, 2003
  4. Lukas
    Replies:
    3
    Views:
    788
    spiff
    Nov 10, 2005
  5. Yevgen Muntyan

    #define ALLOCIT(Type) ((Type*) malloc (sizeof (Type)))

    Yevgen Muntyan, Feb 9, 2007, in forum: C Programming
    Replies:
    10
    Views:
    882
    Yevgen Muntyan
    Feb 13, 2007
Loading...

Share This Page