XSD syntax for declaring an element that cannot have a child elementor other content

Discussion in 'XML' started by Olumide, Apr 4, 2012.

  1. Olumide

    Olumide Guest

    Would this be the proper method of declaring an XML element Foo that
    cannot have a child element or other content?

    <xs:element name="Image" type="xs:string" fixed="" nillable="true" />

    The valid uses of this element in an XML document would be:

    <Foo></Foo>
    <Foo />

    Anything else would be invalid, e.g.:

    <Foo>stuff</Foo>

    Thanks,

    - Olumide


    PS:
    Its just occurred to me that

    <Foo>
    </Foo>

    might be invalid also because of the newline character and other
    whitespace characters that appear between the <Foo> and </Foo>
     
    Olumide, Apr 4, 2012
    #1
    1. Advertising

  2. Re: XSD syntax for declaring an element that cannot have a childelement or other content

    Olumide wrote:
    > Would this be the proper method of declaring an XML element Foo that
    > cannot have a child element or other content?
    >
    > <xs:element name="Image" type="xs:string" fixed="" nillable="true" />
    >
    > The valid uses of this element in an XML document would be:
    >
    > <Foo></Foo>
    > <Foo />
    >
    > Anything else would be invalid, e.g.:
    >
    > <Foo>stuff</Foo>


    Well if you put 'nillable="true"' on the element then valid markup also is
    <Foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:nil="true"/>


    --

    Martin Honnen --- MVP Data Platform Development
    http://msmvps.com/blogs/martin_honnen/
     
    Martin Honnen, Apr 5, 2012
    #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. Peter Aberline

    xsd:any as a child of xsd:all

    Peter Aberline, Apr 5, 2004, in forum: XML
    Replies:
    0
    Views:
    807
    Peter Aberline
    Apr 5, 2004
  2. Bryan Ax
    Replies:
    6
    Views:
    556
    Peter Flynn
    May 17, 2006
  3. Jeff Rodriguez
    Replies:
    23
    Views:
    1,163
    David Schwartz
    Dec 9, 2003
  4. Ian Wilson
    Replies:
    2
    Views:
    565
    Ian Wilson
    Jul 26, 2007
  5. johkar
    Replies:
    0
    Views:
    1,916
    johkar
    Dec 16, 2009
Loading...

Share This Page