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

RE: Empty complexType with mixed="true"

From: Michael Kay <mike@saxonica.com>
Date: Tue, 18 Mar 2008 12:06:33 -0000
To: "'Andrew Welch'" <andrew.j.welch@gmail.com>, <xmlschema-dev@w3.org>
Message-ID: <01ad01c888f0$824be680$6401a8c0@turtle>
RE: Empty complexType with mixed="true"

 
> What's the best way to model "element with text content and 
> attributes"?  For example:
> 
> <foo bar="b" baz="b"> only text allowed </foo>
> 
> I've used this before, but it seems bulky:
> 
> <xs:complexType name="foo">
>     <xs:simpleContent>
>         <xs:extension base="xs:string">
>             <xs:attribute name="bar" type="xs:string"/>
>             <xs:attribute name="baz" type="xs:string"/>
>         </xs:extension>
>     </xs:simpleContent>
> </xs:complexType>
> 
> 
> This thread has suggested you can do this:
> 
>  <xs:complexType name="foo" mixed="true">
>     <xs:attribute name="bar" type="xs:string"/>
>     <xs:attribute name="baz" type="xs:string"/>  </xs:complexType>
> 
> Is that right?   If so, is that shorthand for the above?

They are two types that will validate the same set of instances, but they
are not equivalent. For example, the first one can be restricted to create
another type with a pattern or enumeration facet, the second one can't. They
will also generate a different PSVI, and have different behaviour in
schema-aware queries and stylesheets (one will atomize to xs:string, the
other to xs:untypedAtomic).

I would avoid using mixed content except where both child elements and child
text nodes are allowed.

We had an interesting case with the schema definition for XSLT 2.0, in
defining the type of <xsl:text>. We do this by restricting a more general
type with mixed content, to disallow all children. Some XML Schema
processors have difficulty with this case.

Michael Kay
http://www.saxonica.com/
Received on Tuesday, 18 March 2008 12:07:11 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.