Sometimes an empty value means "use the default value" and sometimes it doesn't ... right?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Sometimes an empty value means "use the default value" and sometimes it doesn't ... right?

Costello, Roger L.
Hi Folks,

Here is a schema that has an Altitude element with a default value of 100, and a Title element with a default value of "Hello World"

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
   
    <xs:element name="Tests">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Test1">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="Altitude" type="xs:integer" default="100" />
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="Test2">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="Title" type="xs:string" default="Hello World" />
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

Here is an instance document that has an empty value for both Altitude and Title

<?xml version="1.0" encoding="UTF-8"?>
<Tests>
    <Test1>
        <Altitude></Altitude>
    </Test1>
    <Test2>
        <Title></Title>
    </Test2>
</Tests>

Since the empty value is not a valid integer, the Altitude element must assume the default value, 100.

Since the empty value is a valid string, the Title element does not assume the default value; its value is the empty string.

Thus sometimes an empty value means "use the default value" and sometimes it doesn't.  Right?

/Roger

Reply | Threaded
Open this post in threaded view
|

Re: Sometimes an empty value means "use the default value" and sometimes it doesn't ... right?

G. Ken Holman
At 2012-08-23 19:04 +0000, Costello, Roger L. wrote:
>Thus sometimes an empty value means "use the default value" and
>sometimes it doesn't.  Right?

What something "means" is up to the semantics of the applications
that act on the content, and to the vocabulary designers who are
trying to impose common understandings of use amongst those employing
the vocabulary.

To add to your list, in UBL an empty value means "error" ... there is
an instance rule that no element shall be empty because it could be
ambiguous between trading partners.

   http://docs.oasis-open.org/ubl/os-UBL-2.0/UBL-2.0.html#d0e3645
   "Use of empty elements within XML instance documents is a
    source of controversy for a variety of reasons."

I hope this helps.

. . . . . . . . . Ken


--
Public XSLT, XSL-FO, UBL and code list classes in Europe -- Oct 2012
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/x/
G. Ken Holman                   mailto:[hidden email]
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal


Reply | Threaded
Open this post in threaded view
|

Re: Sometimes an empty value means "use the default value" and sometimes it doesn't ... right?

Michael Kay
In reply to this post by Costello, Roger L.
The schema spec says that the default value for an element is used when
the element is empty (has no text or element children). It doesn't say
that the default is used when the element would otherwise be invalid.

Michael Kay
Saxonica



On 23/08/2012 20:04, Costello, Roger L. wrote:

> Hi Folks,
>
> Here is a schema that has an Altitude element with a default value of 100, and a Title element with a default value of "Hello World"
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>      
>      <xs:element name="Tests">
>          <xs:complexType>
>              <xs:sequence>
>                  <xs:element name="Test1">
>                      <xs:complexType>
>                          <xs:sequence>
>                              <xs:element name="Altitude" type="xs:integer" default="100" />
>                          </xs:sequence>
>                      </xs:complexType>
>                  </xs:element>
>                  <xs:element name="Test2">
>                      <xs:complexType>
>                          <xs:sequence>
>                              <xs:element name="Title" type="xs:string" default="Hello World" />
>                          </xs:sequence>
>                      </xs:complexType>
>                  </xs:element>
>              </xs:sequence>
>          </xs:complexType>
>      </xs:element>
>
> </xs:schema>
>
> Here is an instance document that has an empty value for both Altitude and Title
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Tests>
>      <Test1>
>          <Altitude></Altitude>
>      </Test1>
>      <Test2>
>          <Title></Title>
>      </Test2>
> </Tests>
>
> Since the empty value is not a valid integer, the Altitude element must assume the default value, 100.
>
> Since the empty value is a valid string, the Title element does not assume the default value; its value is the empty string.
>
> Thus sometimes an empty value means "use the default value" and sometimes it doesn't.  Right?
>
> /Roger
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Sometimes an empty value means "use the default value" and sometimes it doesn't ... right?

Pete Cordell-5
In reply to this post by Costello, Roger L.
It's always seemed a shame to me that <Title></Title> and <Title/> are
semantically equivalent.  In this case it would be handy if <Title></Title>
meant the empty string and <Title/> meant the default.  But it's history
that that ship has sailed through the water under the bridge!

Pete Cordell
Codalogic Ltd
Twitter: http://twitter.com/petecordell
Interface XML to C++ the easy way using C++ XML
data binding to convert XSD schemas to C++ classes.
Visit http://codalogic.com/lmx/ or http://www.xml2cpp.com
for more info
----- Original Message -----
From: "Costello, Roger L." <[hidden email]>
To: <[hidden email]>
Sent: Thursday, August 23, 2012 8:04 PM
Subject: Sometimes an empty value means "use the default value" and
sometimes it doesn't ... right?


Hi Folks,

Here is a schema that has an Altitude element with a default value of 100,
and a Title element with a default value of "Hello World"

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="Tests">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Test1">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="Altitude" type="xs:integer"
default="100" />
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="Test2">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="Title" type="xs:string"
default="Hello World" />
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

Here is an instance document that has an empty value for both Altitude and
Title

<?xml version="1.0" encoding="UTF-8"?>
<Tests>
    <Test1>
        <Altitude></Altitude>
    </Test1>
    <Test2>
        <Title></Title>
    </Test2>
</Tests>

Since the empty value is not a valid integer, the Altitude element must
assume the default value, 100.

Since the empty value is a valid string, the Title element does not assume
the default value; its value is the empty string.

Thus sometimes an empty value means "use the default value" and sometimes it
doesn't.  Right?

/Roger