Re: Element names

Presumably Rick Jellife will be along shortly to point out that this
requirement could be met precisely by a schematron schema  - something
like:

<schema>
	<title>exercise validator</title>
	<pattern name="activityType">
		<!-- root rule -->
		<rule context="/">
			<!-- attribute clauses -->
			<assert test="@distance"><name/> should have a distance
attribute</assert>
			<assert test="@energy"><name/> should have an energy
attribute</assert>
			<assert test="count(@*) != 2"><name/> has an illegal
attribute</assert>
		</rule>
	</pattern>
</schema>

The more I use XML Schema and schematron the more complementary I find
them.

Francis.

Noah_Mendelsohn@lotus.com wrote:
> 
> You might find what you need in substitution groups [1] and [2].  You
> might find that by making a substitution group <waysOfGettingAround> that
> includes both <stroll> and <walk> (and perhaps others), that you can do
> what you want.   Within limits, you can provide for a controlled
> relationship on the types of <stroll> and <walk>, but you need to be
> careful with the declaration of the type for <waysOfGettingAround> itself.
>  See the references below for the details.
> 
> Please do let us know if this mechanism meets your needs, as we are trying
> to judge the effectiveness of our design.
> 
> [1] http://www.w3.org/TR/xmlschema-0/#SubsGroups
> [2] http://www.w3.org/TR/xmlschema-1/#key-equivalenceClass
> 
> ------------------------------------------------------------------------
> Noah Mendelsohn                                    Voice: 1-617-693-4036
> Lotus Development Corp.                            Fax: 1-617-693-8676
> One Rogers Street
> Cambridge, MA 02142
> ------------------------------------------------------------------------
> 
> Daniel Acton <dacton@itouch.co.za>
> Sent by: xmlschema-dev-request@w3.org
> 12/02/00 01:56 PM
> 
> 
>         To:     xmlschema-dev@w3.org
>         cc:     (bcc: Noah Mendelsohn/CAM/Lotus)
>         Subject:        Element names
> 
> Hi.
> 
> I am trying to make an xmlschema to vaalidate different instances of an
> xml document. Do I have to explicitly name the elements in the schema, or
> can I make an element be recognised by it's attributes. Here's a scenario:
> 
> --First instance--
> <Dog>
>   <sleep time="10" energy="5joules"/>
>   <walk time="10km" energy="10joules"/>
>   ...
> </Dog>
> 
> --Second instance--
> <Cat>
>   <sleep time="25" energy="14joules"/>
>   <stroll distance="2km" energy="50joules"/>
>   ...
> </Cat>
> 
> --Schema--
> 
> <xsd:element name="sleep" type="activityType"/>
> <xsd:element name="walk" type="activityType"/>
> 
> <xsd:complexType="activityType">
>   <xsd:attribute name="distance" type="xsd:string"/>
>   <xsd:attribute name="energy" type="xsd:string"/>
> </xsd:complexType>
> 
> The above schema, I assume, and once again am standing to correction,
> would validate the first instance, but not the second. I have tried
> something similar, and have received the following:
>  > Element 'stroll' not expected
> 
> Is there a way I can tell the schema to expect an element with those
> attributes, but not explicitly state the name?
> 
> Thank you in advance
> Daniel

-- 
Francis Norton.

why not?

Received on Tuesday, 5 December 2000 04:26:58 UTC