- From: Arnold, Curt <Curt.Arnold@hyprotech.com>
- Date: Fri, 5 Jan 2001 13:41:34 -0700
- To: "'Imran Rashid'" <imranr@wolfram.com>
- Cc: "'xml-dev@lists.xml.org'" <xml-dev@lists.xml.org>, "'www-xml-schema-comments@w3.org'" <www-xml-schema-comments@w3.org>
Yes, xsi:type appears in the instance document and explicitly asserts the type of the element. See Section 4.3 of the Primer (http://www.w3.org/TR/xmlschema-0/) and Section 2.6.1 of (http://www.w3.org/TR/xmlschema-1/) Suprisingly, whether the type asserted by xsi:type has to be related to the declared type of the element is not explicitly stated in the Structure Draft. You can use the block attribute of the element definition to prevent an instance from providing an xsi:type that is a restriction, an extension or both of the specified type. However, if xsi:type doesn't have to be related to the specified type then there does not appear to be a mechanism to prevent an assertion that conflicts with the defined type. XSV 1.173/1.80 appears seem to require that the type specified by xsi:type to be a subtype of the declared type. Oracle's XML Schema Processor for Java didn't care. Here is a sample document and schema: <tests xmlns="http://www.example.org/xsitype" xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"> <test>This is a string</test> <test xsi:type="xsd:double">3.1415926E30</test> <test xsi:type="xsd:double">This is not a double</test> </tests> ---- <xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" xmlns="http://www.example.org/xsitype" targetNamespace="http://www.example.org/xsitype"> <xsd:element name="test" type="xsd:string"/> <xsd:element name="tests"> <xsd:complexType> <xsd:sequence minOccurs="0" maxOccurs="unbounded"> <xsd:element ref="test"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> XSV will report two errors that xsd:double is not a subtype of xsd:string. [Note: XSV requires a DOCTYPE and Oracle has problems if you include one, so it is assumed that you add or remove the DOCTYPE depending on which processor you are using] Oracle will report an error with the "This is not a double" double and will report no errors if that line is removed. For this instance and schema: <tests xmlns="http://www.example.org/xsitype" xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"> <test>This is a string</test> <test xsi:type="number">3.1415926E30</test> <test xsi:type="number">This is not a double</test> </tests> ---------- <!DOCTYPE xsd:schema SYSTEM 'XMLSchema.dtd'> <xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" xmlns="http://www.example.org/xsitype" targetNamespace="http://www.example.org/xsitype"> <xsd:simpleType name="number"> <xsd:restriction base="xsd:string"> <xsd:pattern value="[0-9,.,E]*"/> </xsd:restriction> </xsd:simpleType> <xsd:element name="test" type="xsd:string"/> <xsd:element name="tests"> <xsd:complexType> <xsd:sequence minOccurs="0" maxOccurs="unbounded"> <xsd:element ref="test"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> Oracle will throw a null pointer exception and XSV say the document passed (though it should have generated a message for the "This is not a double") The schema spec should explicitly state whether xsi:type has to be a subtype of the defined type (either a restriction, extension or union member). If it doesn't, then block needs to have a new value to block unrelated type specifications.
Received on Friday, 5 January 2001 15:47:36 UTC