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

Received on Thursday, 23 August 2012 19:04:34 UTC