[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: schemas: can I restrict an elem's content based on att value?

  • From: "Arnold, Curt" <Curt.Arnold@h...>
  • To: 'Imran Rashid' <imranr@w...>
  • Date: Fri, 05 Jan 2001 13:41:34 -0700

doctype xsd
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. 

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.