xs:nil and xs:string
Posted: Fri Jul 07, 2006 9:33 am
Hello
can anybody explain me why xsi:nil is necessary for an empty element when the type is date, but when the type is string it works without.
The first XML is valid against the following schema
<el xsi:noNamespaceSchemaLocation="schema.xsd">
<element_1/>
</el>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="a">
<xs:sequence>
<xs:element name="element_1" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="el" type="a"/>
</xs:schema>
When I change the type from string to date the XML is not valid anymore.
To get it valid again the schema and the XML must be changed.
<el xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="schema.xsd">
<element_1 xsi:nil="true"/>
</el>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="a">
<xs:sequence>
<xs:element name="element_1" type="xs:date" nillable="true"/>
</xs:sequence>
</xs:complexType>
<xs:element name="el" type="a"/>
</xs:schema>
Thanks
Stephan
can anybody explain me why xsi:nil is necessary for an empty element when the type is date, but when the type is string it works without.
The first XML is valid against the following schema
<el xsi:noNamespaceSchemaLocation="schema.xsd">
<element_1/>
</el>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="a">
<xs:sequence>
<xs:element name="element_1" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="el" type="a"/>
</xs:schema>
When I change the type from string to date the XML is not valid anymore.
To get it valid again the schema and the XML must be changed.
<el xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="schema.xsd">
<element_1 xsi:nil="true"/>
</el>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="a">
<xs:sequence>
<xs:element name="element_1" type="xs:date" nillable="true"/>
</xs:sequence>
</xs:complexType>
<xs:element name="el" type="a"/>
</xs:schema>
Thanks
Stephan