Schema-related markup in XML documents
xsi:nil, xsi:type, xsi:schemaLocation,
and xsi:noNamespaceSchemaLocation.
The schema-related markup in XML documents includes the following elements:
xsi:nil
When an
XML element is set to xsi:nil in the XML document
instance, its related dynamic class field is set to null. The isunknown operator
applied on this field returns true. In other words,
when an XML object is serialized via the driver.writeObject method,
the following information is added to this object:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Example of mapping xsi:nil in an XML document
The
following example demonstrates the mapping of xsi:nil in
an XML document. The rule detectPersonWithMissingAddress uses
the isunknown keyword to find a person whose address
is not known.
In this example:
xsiis the namespace namehttp://www.w3.org/2001/XMLSchemainstance is the URLnilis one element of the namespace
Here is the schema:
<element name="person">
<complexType>
<sequence>
<element name="surname"/>
<element name="address" nillable="true"/>
</sequence>
<complexType>
</element>
Here is the excerpt from an XML document:
<person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<surname>Smith</surname>
<address xsi:nil="true"/>
</person>
And here is the rule:
rule detectPersonWithMissingAddress
{
when {
Person ( address isunknown );
}
then {
...
}
}
XML namespaces are designed to provide universally unique names for elements and attributes. Developers can use them to carry out the following actions:
Combine fragments from different documents without any naming conflicts.
Write reusable code modules that can be called for specific elements and attributes. Universally unique names guarantee that such modules are called only for the correct elements and attributes.
Define elements and attributes that can be reused in other schemas without any risk of name conflicts.
xsi:type
To refine the type of an element in the XML document, you can use xsi polymorphism. This feature substitutes a subtype for the standard type of the element.
Example of mapping xsi:type in an XML document
The following example demonstrates how to use xsi polymorphism. The example uses a schema and an excerpt from an XML document.
Here is the schema:
<element name="person" type="person"/>
<complexType name=" person " >
<sequence>
<element name="name">
<element name="surname">
</sequence>
</complexType>
<complexType name=" inhabitant ">
<complexContent>
<extension base="person">
<sequence>
<element name="address"/>
</sequence>
</extension>
</complexType>
And here is an excerpt from an XML document:
<person xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xsi:type="inhabitant">
<name>John</name>
<surname>Smith</surname>
<address>123 Downing Street, London</address>
</person>
xsi:schemaLocation and xsi:noNamespaceSchemaLocation
These functions are supported by the parser. However, the resulting information is not used in XML binding.