XML schema validation and ignorable whitespace
XML schema validation removes ignorable whitespace from a document.
According to the XML standard, whitespace is space characters (U+0020), carriage returns (U+000D), line feeds (U+000A), or tabs (U+0009) that are in the document to improve readability. When any of these characters appear as part of a text string, they are not considered to be whitespace.
Ignorable whitespace is whitespace that can be eliminated from the XML document. The XML schema document determines which whitespace is ignorable whitespace. If an XML document defines an element-only complex type (an element that contains only other elements), the whitespace between the elements is ignorable. If the XML schema defines a simple element that contains a non-string type, the whitespace within that element is ignorable.
description
element in the
sample product.xsd XML schema document is defined like this: <xs:element name="description" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0" />
<xs:element name="details" type="xs:string" minOccurs="0" />
<xs:element name="price" type="xs:decimal" minOccurs="0" />
<xs:element name="weight" type="xs:string" minOccurs="0" />
…
</xs:complexType>
</xs:element>
The description
element has an element-only complex
type because it contains only other elements. Therefore, whitespace
between elements in a description
element is ignorable
whitespace. The price
element can also contain ignorable
whitespace because it is a simple element that contains a non-string
type.
Suppose that schema PRODUCT
is registered in the
XML schema repository (XSR).
CREATE TABLE MYPRODUCT (
PID VARCHAR(10) NOT NULL PRIMARY KEY,
NAME VARCHAR(128),
PRICE DECIMAL(30,2),
PROMOPRICE DECIMAL(30,2),
PROMOSTART DATE,
PROMOEND DATE,
DESCRIPTION XML)
<product xmlns="http://posample.org" pid="110-100-01" >
<description>
<name>Anvil</name>
<details>Very heavy</details>
<price> 9.99 </price>
<weight>1 kg</weight>
</description>
</product>
<product xmlns="http://posample.org" pid="110-100-01"><description><name>Anvil
</name><details>Very heavy</details><price>9.99</price><weight>1 kg</weight>
</description></product>
The PRODUCT
schema
defines the whitespace around the name
, details
, price
,
and weight
elements, and the whitespace within the
price element as ignorable whitespace, so XML schema validation removes
it.