XSD that accepts empty value

K

kieroneil

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
 
M

Martin Honnen

kieroneil said:
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.
 
U

usenet

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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top