xs:nil and xs:string
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 1
- Joined: Thu Jul 06, 2006 4:20 pm
xs:nil and xs:string
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
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Post by sorin_ristache »
Hello,
The xs:string type includes all the string values allowed by the xs:string definition of the XML Schema specification and this includes the empty string but the xs:date type does not include such an empty value. That means an xs:date element can contain no text node child only if that element is defined as nillable in the XML Schema of that XML document.
Regards,
Sorin
The xs:string type includes all the string values allowed by the xs:string definition of the XML Schema specification and this includes the empty string but the xs:date type does not include such an empty value. That means an xs:date element can contain no text node child only if that element is defined as nillable in the XML Schema of that XML document.
Regards,
Sorin
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service