XSD that accepts empty value

Discussion in 'XML' started by kieroneil, Feb 25, 2008.

  1. kieroneil

    kieroneil Guest

    I am having a problem with validating a document.

    Here is the segment that is causing the problem:
    <INSERT>
    <HEADERFIELDS>
    <TABLENAME>AppDetails</TABLENAME>
    <PARENTROW>01</PARENTROW>
    <CURRENTROW>001</CURRENTROW>
    </HEADERFIELDS>
    <DATAFIELDS>
    <ProductID>07</ProductID>
    <CashPrice>500</CashPrice>
    <BranchID>54</BranchID>
    <AmountRequested>500</AmountRequested>
    <AmountFinanced>500</AmountFinanced>
    <DetailTerm>360</DetailTerm>
    <NumberOfPayments/>
    <HMDALoanPurpose>1</HMDALoanPurpose>
    </DATAFIELDS>
    </INSERT>

    The NumberOfPayments element is causing it not to validate.

    This is how it looks in the XSD:
    <xs:element name="NumberOfPayments" type="xs:int"/>

    This is the reference to it:
    <xs:element ref="NumberOfPayments" minOccurs="0"/>

    I would like it to accept being empty as well as Int values.

    How do I do this?

    THanks in advance,
    Kier
    Jacksonville, FL
     
    kieroneil, Feb 25, 2008
    #1
    1. Advertising

  2. kieroneil wrote:

    > The NumberOfPayments element is causing it not to validate.
    >
    > This is how it looks in the XSD:
    > <xs:element name="NumberOfPayments" type="xs:int"/>
    >
    > This is the reference to it:
    > <xs:element ref="NumberOfPayments" minOccurs="0"/>
    >
    > I would like it to accept being empty as well as Int values.
    >
    > How do I do this?


    The usual way with W3C schemas is to use
    <xs:element ref="NumberOfPayments" nillable="true"/>
    and then to use
    <NumberOfPayments xsi:nil="true"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
    in the XML instance document.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Feb 25, 2008
    #2
    1. Advertising

  3. kieroneil

    Guest

    On 25 Feb, 14:39, Martin Honnen <> wrote:
    > kieroneil wrote:
    > > The NumberOfPayments element is causing it not to validate.

    >
    > > This is how it looks in the XSD:
    > > <xs:element name="NumberOfPayments" type="xs:int"/>

    >
    > > This is the reference to it:
    > > <xs:element ref="NumberOfPayments" minOccurs="0"/>


    One option is to use xs:union. An XML schema snippet for that might
    look like:

    <xs:element name="NumberOfPayments">
    <xs:simpleType>
    <xs:union memberTypes="xs:int">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:enumeration value=""/>
    </xs:restriction>
    </xs:simpleType>
    </xs:union>
    </xs:simpleType>
    </xs:element>

    HTH,

    Pete Cordell
    Codalogic
    For XML C++ data binding visit http://www.codalogic.com/lmx/
     
    , Feb 26, 2008
    #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. Markus
    Replies:
    1
    Views:
    1,109
    Markus
    Nov 22, 2005
  2. Rick Razzano

    XSD document for XSD defintion

    Rick Razzano, Sep 26, 2003, in forum: XML
    Replies:
    1
    Views:
    493
    C. M. Sperberg-McQueen
    Sep 26, 2003
  3. Replies:
    1
    Views:
    864
    Martin Honnen
    Jan 14, 2004
  4. Peter Aberline

    xsd:any as a child of xsd:all

    Peter Aberline, Apr 5, 2004, in forum: XML
    Replies:
    0
    Views:
    794
    Peter Aberline
    Apr 5, 2004
  5. leon breedt
    Replies:
    3
    Views:
    197
    Jamis Buck
    Jan 23, 2005
Loading...

Share This Page