How do I specify a nullable xs:int?

Discussion in 'XML' started by jacksuyu@gmail.com, Nov 22, 2005.

  1. Guest

    I have one xsd which defines element "Port" as "xs:int", and there are
    bunch of xml files use "Port" element. But a lot of those files
    contains <Port/>, which is treated invalid in xml validation.

    I am wondering whether there is anyway to specify nullable integer, say
    treat <Port/> the same as <Port>0</Port>?

    Thanks in advance.
    , Nov 22, 2005
    #1
    1. Advertising

  2. wrote:


    > I am wondering whether there is anyway to specify nullable integer, say
    > treat <Port/> the same as <Port>0</Port>?


    Yes, see <http://www.w3.org/TR/xmlschema-1/#declare-element>, you can do
    <xs:element name="Port" type="xs:integer" nillable="true" />
    and then the instance needs to have e.g.
    <Port xsi:nil="true"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />

    <http://www.w3.org/TR/xmlschema-1/#xsi_nil> explains that too.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Nov 22, 2005
    #2
    1. Advertising

  3. jacksuyu writes:

    > I am wondering whether there is anyway to specify nullable integer, say
    > treat <Port/> the same as <Port>0</Port>?


    That's a defaulted xs:int, not a nullable one, and yes, just declare

    <xs:element name="Port" type="xs:int" default="0"/>

    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, Nov 23, 2005
    #3
    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. Schnoffos
    Replies:
    2
    Views:
    1,198
    Martien Verbruggen
    Jun 27, 2003
  2. Hal Styli
    Replies:
    14
    Views:
    1,615
    Old Wolf
    Jan 20, 2004
  3. arun
    Replies:
    8
    Views:
    433
    Dave Thompson
    Jul 31, 2006
  4. aling
    Replies:
    8
    Views:
    933
    Jim Langston
    Oct 20, 2005
  5. Replies:
    9
    Views:
    420
    James Kanze
    Apr 17, 2007
Loading...

Share This Page