Re: [Moderator Action] nullable vs empty tag: a problem case and need help..

Dwifiandika FAULUS <dfaulus@mda.ca> writes:

> An element in my schema is based on the following simpleType:
> 
>  <xsd:element name="APPLICANT_UPRN" type="nlis:UprnType" minOccurs="0"/>
> 
> <xsd:simpleType name="UprnType" base="xsd:positiveInteger">
>      <xsd:minInclusive value="1"/>
>      <xsd:maxInclusive value="99999"/>
> </xsd:simpleType>
> 
> In a particular case, a client send a message which in which this tag
> happens to be empty:
> 
> <MESSAGE ...>
>   .....
>   <APPLICANT_UPRN/>
>   .....
> </MESSAGE>
> 
> My system will parse the xml against this schema, and it is currently using 
>   the latest version of the oracle schema processor. 
> 
> Also, the system should allow the tag to be empty. 
> 
> The Problem:
> -------------------
> 
> The parser/validator rejects the message indicating that the tag can not be
> empty:
> ie.
>      <Line 30, Column 26>: XSD-2025: (Error) Invalid text ' ' in element:
> 'APPLICANT_UPRN'
> 
> I read the schema primer, and the suggestion is to use
> 'nullable="true"' attribute to the schema element and specifying
> <APPLICANT_UPRN xsi:null="true"/> in the message.
> 
> While this is working, however, the interface/ICD that we already
> published to various external clients does not prescribes this
> method of specifying the nullability.  Ie. it does not allow
> 'xsi:null="true"' addition to a null tag. (since it requires changes
> in the message interface).  And we prefer to keep the ICD as it is
> right now (a bit to late to change w/o affecting a lot of things).
> 
> So the questions:
> 
> 1. Is there another alternative in the schema that we can use
> without changing the message ? (ie. we want to keep the
> <APPLICANT_UPRN/> format).

Yes, there is -- change your type definition as follows [Note you
appear to be using an out-of-date version of XML Schema -- the
proposed solution will only work if you upgrade your processor (see
[1] for a list) and syntax (see [2] for an automated upgrade service)
to the current syntax:

<xsd:simpleType name="UprnType">
  <xsd:union>
   <xsd:simpleType>
     <xsd:restriction base="xsd:positiveInteger">
      <xsd:minInclusive value="1"/>
      <xsd:maxInclusive value="99999"/>
    </xsd:restriction>
   </xsd:simpleType>
   <xsd:simpleType>
     <xsd:restriction base="xsd:token">
      <xsd:enumeration value=""/>
    </xsd:restriction>
   </xsd:simpleType>
 </xsd:union>
</xsd:simpleType>

Now you are allowed integers and the empty string as values.

> 2. I find out that for tags that are 'simple', this problem does not occur.
>     Ie. the following tag does not have the problem mention above:
>
> <xsd:element name="ORIGINATOR_DIGITAL_SIGNATURE"
> type="nlis:DigitalSignatureType" minOccurs="0"/>
> <xsd:simpleType name="DigitalSignatureType" base="xsd:string"/>

This is because strings can be empty, but integers can't.

ht

[1] http://www.w3.org/XML/Schema.html
[2] http://www.w3.org/2000/09/webdata/xsupgrade
-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
          W3C Fellow 1999--2001, part-time member of W3C Team
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/

Received on Saturday, 20 January 2001 06:55:13 UTC