∟Overriding Element Type to Empty Content - nillable
This section describes a tutorial example on what is a nillable element and how to declare an element to be nillable.
Sometimes when constructing an element in an XML document, you may want to override the element type defined
in the schema to say no element content is provided. This can be done by using the special attribute "nil="true""
to override the content type defined in the schema.
For example, elements representing sales order may defined to have a "shipDate" child element, which must have "date"
as its content. However, orders that are not shipped yet will have no content in "shipDate". The "shipDate" element
in those orders can use the special attribute "nil="true"".
Rules on overriding the element type to say no element content is provided using the special attribute "nil="true"":
1. The element must be declared with "nillable="true"" in the schema.
Note that "nillable="true"" must be added to the element declaration component, not to the type definition component.
2. Declare a new namespace prefix in the XML document called, "xsi", with a special attribute on the root element:
"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"". This is needed to provide the namespace prefix "xsi" for the next change.
3. In XML document, add the special attribute "xsi:nil="true"" to the element.
4. No content (no child element, or text content) should be include in that element.
5. Attributes of that element is not affected by "xsi:nil="true"".
Below is a tutorial sample schema named order.xsd that has the "shipDate" element
declared as "nillable":