W3C home > Mailing lists > Public > xmlschema-dev@w3.org > November 2001

Re: Problem with pattern and empty element

From: Jeni Tennison <jeni@jenitennison.com>
Date: Fri, 16 Nov 2001 12:11:48 +0000
Message-ID: <1487926908.20011116121148@jenitennison.com>
To: "kfricovsky" <kfricovsky@fusebox.com>
CC: xmlschema-dev@w3.org
Hi Kevin,

> I am using XML SPY to validate my XML using the SCHEMA I created.
> The problem I am having is leaving this element as an empty element,
> like <XXX/>. XML SPY says that the XML doc isn't well formed unless
> I insert a value conforming to my pattern.
>
> Is there a way to define a NULL value or some kind of default value
> that will allow this element to be left empty?

The other alternative to changing the regular expression is to make
the element nillable:

<xsd:element name="XXX" nillable="yes">
        <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                        <xsd:pattern value="([0-9]+|[A-Z]+)+" />
                </xsd:restriction>
        </xsd:simpleType>
</xsd:element>

and then use xsi:nil on the instance:

<XXX xsi:nil="true" />

This specifically highlights the fact that XXX is a null value.

Alternatively you can add a default value that matches the regular
expression:

<xsd:element name="XXX" default="YYY">
        <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                        <xsd:pattern value="([0-9]+|[A-Z]+)+" />
                </xsd:restriction>
        </xsd:simpleType>
</xsd:element>

If the element is empty in the instance, then it will be 'seen' as if
it has the value YYY.

It depends on what information you want the application receiving the
PSVI to have. Likely as not you don't have an application receiving
the PSVI, so it doesn't really matter. But if you do, then there is a
distinct difference between "a value that is an empty string", "a nil
value" and "the value 'YYY'" and which alternative you choose depends
on which of those values you want the application to see.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Friday, 16 November 2001 07:12:47 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:14:55 UTC