null vs empty in XML Schemas

Hi Folks,

I have two questions: 
1. What is the difference between null and empty?
2. How is nullable/null used? 

My understanding of the difference between null and empty is:

- If an element is declared to be of type empty then in the XML instance
  document the content of that element is a string of length zero.

- If an element is declared with nullable="true" then in the XML
instance
  document if the element has xsi:null="true" then this element
  has undefined content.

Is this a correct understanding of the difference between empty and
null?

Below is my understanding of how nullable/null is to be used:

Here is an example XML Schema snippet declaring an element (middle) with
nullable="true":

<element name="PersonName">
      <type>
            <element name="forname" type="NMTOKEN"/>
            <element name="middle" type="NMTOKEN" nullable="true"/>
            <element name="surname" type="NMTOKEN"/>
      </type>
</element>

Here is an example XML instance document conforming to the above schema
snippet, where the middle element has been set to a null value:

<PersonName>
      <forename>John</forename>
      <middle xsi:null="true"/>
      <surname>Doe</surname>
</PersonName>

Thus, middle may contain a NMTOKEN value, or it may indicate that there
is no defined value.  Is this the correct usage of nullable/null?  My
reason for asking is because in the XML Schema spec, after nullable/null
is discussed there is an Issue section stating:

"Issue (nullRequiresEmpty): Is it a precondition for being nullable that
the element's contentType allow no content? If not, then more needs to
be said above, if so, this needs to be spelled out."

This isn't consistent with the above example.  I thought that an element
declared with nullable="true" can have a value in the instance document
when a value is available.  When no value is available then we can
indicate this in the instance document by setting xsi:null="true".  This
Issue seems to say that elements declared with nullabe="true" can never
have a value in the instance document.  Thus, the middle element can
never have a value.  Wherein lies the truth?  /Roger

Received on Sunday, 2 January 2000 07:56:32 UTC