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

Re: two elements with the same name but different types

From: George Cristian Bina <george@oxygenxml.com>
Date: Mon, 20 Mar 2006 15:27:27 +0200
Message-ID: <441EADBF.4030609@oxygenxml.com>
To: andrew welch <andrew.j.welch@gmail.com>
Cc: xmlschema-dev@w3.org
schema two elements same name

Hi Andrew,

What you are trying to do is not possible with XML Schema. If you have 
two or more element declarations then you must use a global type 
definition for them, see
http://www.w3.org/TR/xmlschema-1/#cos-element-consistent

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


andrew welch wrote:
> Hi,
> 
> I'm trying to model the following in a schema:
> 
> <head>
>   <title>the title<title>
>   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
>   <meta name="fixed_1" content="variable"/>
>   <meta name="fixed_2" content="variable"/>
>   <meta name="fixed_3" content="variable"/>
>   <meta name="fixed_4" content="fixed_5"/>
> </head>
> 
> Here the first <meta> has two fixed value attributes, then the
> following three have fixed name attributes (which are all different
> fixed values) but any content attributes.  The last meta contains two
> fixed value attributes, like the first.
> 
> Is this possible to model with XML Schema?  Currently I have:
> 
> <xs:element name="head">
>   <xs:complexType>
>     <xs:sequence>
>       <xs:element ref="title"/>		
> 					
>       <xs:element name="meta">
>         <xs:complexType>
>           <xs:attribute name="http-equiv" type="xs:string"
> fixed="Content-Type"/>
>           <xs:attribute name="content" type="xs:string"
> fixed="text/html; charset=utf-8"/>
>         </xs:complexType>
>       </xs:element>
> 					
>       <xs:element name="meta">
>         <xs:complexType>
> 	  <xs:attribute name="name" type="xs:string" fixed="fixed_1"/>
>           <xs:attribute name="content" type="xs:string"/>
>         </xs:complexType>
>       </xs:element>
> 					
>       <xs:element name="meta">
>         <xs:complexType>
>           <xs:attribute name="name" type="xs:string" fixed="fixed_2"/>
>           <xs:attribute name="content" type="xs:string"/>
> 	</xs:complexType>
>       </xs:element>
> 
> ....
>       <xs:element name="meta">
>         <xs:complexType>
>           <xs:attribute name="name" type="xs:string" fixed="fixed_4"/>
>           <xs:attribute name="content" type="xs:string" fixed="fixed_5"/>
> 	</xs:complexType>
>       </xs:element>
> 
> I read that this is ok as long as the element definitions are local
> and not global, but I still get the error:
> 
> "two elements with the same name <meta> but different types appear in
> the content model"
> 
> The other problem is defining when "fixed_4" is the value for the name
> attribute, "fixed_5" must be the value for the content attribute. 
> Isn't this a co-occurrence constraint?  In which case it's not
> possible to do this in XML Schema...?
> 
> I'm writing this schema within an <xsl:import-schema> element in XSLT
> 2.0, so it's not possible to use Relax NG here.  This is to validate
> the output as it's being generated by the transform... the alternative
> is to do the validation as a seperate step in the pipeline, which
> might be the only option....
> 
> thanks
> andrew
> 
> 
Received on Monday, 20 March 2006 13:25:19 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
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-2007 All Rights Reserved.