Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: Facets

From: <richard.liu@---.--->
To: <kbuchcik@---------.-->, <Farid.Mahini@------.--->
Date: 2/18/2005 12:49:00 PM
This seems to do what Farid wanted, and it validates in xmlspy 2005 sp2:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" =
elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:element name="measurements">
		<xs:annotation>
			<xs:documentation>Testing my understanding of xs:key and xs:keyref.  =
If this works, it could become the basis for translating an FDDL into an =
XML schema.</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:sequence>
				<xs:element name="validTypes">
					<xs:complexType>
						<xs:sequence>
							<xs:element name="validType" type="xs:string" =
maxOccurs="unbounded"/>
						</xs:sequence>
					</xs:complexType>
				</xs:element>
				<xs:element name="measurement" maxOccurs="unbounded">
					<xs:complexType>
						<xs:sequence>
							<xs:element name="name" type="xs:string"/>
							<xs:element name="type" type="xs:string"/>
						</xs:sequence>
					</xs:complexType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
		<xs:key name="validType">
			<xs:selector xpath="validTypes/validType"/>
			<xs:field xpath="."/>
		</xs:key>
		<xs:keyref name="measurementType" refer="validType">
			<xs:selector xpath="measurement"/>
			<xs:field xpath="type"/>
		</xs:keyref>
	</xs:element>
</xs:schema>

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2005 sp2 U (http://www.altova.com) by Rene =
Brunner (UBS AG) -->
<measurements xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" =
xsi:noNamespaceSchemaLocation="D:\My =
Documents\Work\WBml\Forms\Schema\keyrefTest.xsd">
	<validTypes>
		<validType>analog</validType>
		<validType>digital</validType>
		<validType>bus</validType>
		<validType>undefined</validType>
	</validTypes>
	<measurement>
		<name>airflow</name>
		<type>analog</type>
	</measurement>
	<measurement>
		<name>heading</name>
		<type>digital</type>
	</measurement>
</measurements>

Regards,
Richard

> -----Original Message-----
> From: xmlschema-dev-request@w...
> [mailto:xmlschema-dev-request@w...]On Behalf Of Kasimier Buchcik
> Sent: Thursday, February 17, 2005 20:40
> To: Farid.Mahini@L...
> Cc: xmlschema-dev@w...
> Subject: Re: Facets
> 
> 
> 
> Hi,
> 
> Farid.Mahini@L... wrote:
> > Thank you for your comment.
> > 
> > I am planning on using this method (actually currently in 
> the middle of
> > Michael Kay's XSLT2.0 book) in the way you mentioned it:
> > 
> > I am creating XML files for running tests on various 
> 'boxes' which have
> > different configurations (#of cards, channels, so on). I 
> was planning on
> > using the XSLT to create the hardware dependant schema 
> using user hardware
> > selection.  It seems I am on the righttrack on that section 
> of the task. 
> > 
> > However, within each XML document, the user defines their own set of
> > definitions to be used as enum values.  Michael Kay 
> suggested using the
> > 'key/keyref' elements; I tried it, but XMLSpy  seems to 
> validate it even
> > though I intentionally used an invalid attribute. I am new 
> at this and could
> > be my code.  Please point my error in the following example 
> I used to test
> > the key/keyref element? 
> > 
> > The schema:
> > <xs:schema  ....>
> > 	<xs:element name="Measurements">
> > 		<xs:complexType>
> > 			<xs:sequence>
> > 				<xs:element name="AAA" type="myAAA"/>
> > 				<xs:element name="BBB" type="myBBB"/>
> > 			</xs:sequence>
> > 		</xs:complexType>
> > 		<xs:key name="myId">
> > 			<xs:selector xpath="./AAA/a"/>
> > 			<xs:field xpath="@a"/>
> > 		</xs:key>
> > 		<xs:keyref name="myIdref" refer="myId">
> > 			<xs:selector xpath="./BBB/b"/>
> > 			<xs:field xpath="@b"/>
> > 		</xs:keyref>
> > 	</xs:element>
> > 	<xs:complexType name="myAAA">
> > 		<xs:sequence>
> > 			<xs:element name="a" maxOccurs="unbounded">
> > 				<xs:complexType>
> > 					<xs:attribute name="id"
> > type="xs:string" use="required"/>
> > 				</xs:complexType>
> > 			</xs:element>
> > 		</xs:sequence>
> > 	</xs:complexType>
> > 	<xs:complexType name="myBBB">
> > 		<xs:sequence>
> > 			<xs:element name="b" maxOccurs="unbounded">
> > 				<xs:complexType>
> > 					<xs:attribute name="idref"
> > type="xs:string" use="required"/>
> > 				</xs:complexType>
> > 			</xs:element>
> > 		</xs:sequence>
> > 	</xs:complexType>
> > </xs:schema>
> > 
> > 
> > The XML input doucment:
> > <Measurements .....>
> >   <AAA> 
> >     <a id="x"/> 
> >     <a id="y"/> 
> >   </AAA> 
> >   <BBB> 
> >     <b idref="x"/> 
> >     <b idref="y"/> 
> >     <b idref="z"/>    // should cause an error since only 
> 'x' and 'y' are
> > valid choices.
> >   </BBB>
> > 
> > </Measurements>
> [...]
> 
> XMLSpy does not evaluate this correctly. The XPath expression 
> of the IDC
> fields used here should resolve to the attributes "a" or "b" only.
> If those XPath expressions are substituted for "@id" and 
> "@idref" I get
> keyref error you expected with Libxml2, Xerces 2.6.2 and XSV 2.7.
> 
> Regards,
> 
> Kasimier
> 
> 

From brs@i... Mon Feb 21 11:22:12 2005
Received: from lisa.w3.org ([128.30.52.41])
	by frink.w3.org with esmtp (Exim 4.34)
	id 1D3Bdk-0000Jq-72
	for xmlschema-dev@l...; Mon, 21 Feb 2005 11:22:12 +0000
Rece


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent