|
From: Tom W. <dev...@to...> - 2003-04-02 18:10:49
|
On Wed, 2 Apr 2003 06:05:07 -0500 (EST), Peter C. Chapin <pc...@ec...> wrote: > I'm not familiar with <xs:anyType>. It is the root of the datatype hierarchy - <element type="xs:anyType"/>. > I do have a reference that talks about > the <xs:any> element, however. It gives an example like this: > > <xs:element name="XHTMLSection> > <xs:complexType> > <xs:sequence> > <xs:any namespace="http://www.w3.org/1999/xhtml" > minOccurs="0" maxOccurs="unbounded" > processContents="skip"/> > </xs:sequence> > </xs:complexType> > </xs:element> > > This apparently allows an <XHTMLSection> element to contain any elements > from XHTML. The processContents attribute controls how the contents of > that element are validated. The value of "skip" means no validation, but > other options are possible (namely "strict" and "lax"). > > Is this the sort of thing we're talking about? Yes! <xs:any> and <xs:anyAttribute> allow for any content to be extended to the schema. The difference with <elem type="xs:anyType"> is that the element name is defined and it is only the content of the element itself that varies. It works in a similar way to <elem xsi:type=".."> in the instance document. For example: A schema doc defines weatherType, a complexType instantiated as <temperature> <value units="C">20</value> <notes>Roll on summer</notes> </temperature> in the namespace http://weather.sourceforge.net And in the astroXML schema within <observation> the temperature element is defined as <xsd:element name="weather" type="xsd:anyType" minOccurs="0"/> The instance would then be: <observation xmlns="http://xmlastro.sourceforge.net" xmlns:w="http://weather.sourceforge.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="xmlastro.sourceforge.net astroxml.xsd http://weather.sourceforge.net weather.xsd"> <weather xsi:type="w:weatherType"> <w:temperature> <w:value units="C">20</w:value> <w:notes>Roll on summer</notes> </w:temperature> </weather> </observation> As with <xs:any>, the weather schema is added at instance creation, so different content models for weather can be used, with the only difference being the element itself <weather> has been defined in the astroXML schema. > Note that apparently the namespace attribute can be left off so that the > content of the element can be from any namespace. The reference I have > even says that this is a nice thing to do during development for exactly > the reasons we have been discussing. Using this approach does sound good > and it may be a good way to handle <notes> permanently. <xs:any> has the advantage of allowing any content, so I agree that during development this is probably a better option and more extensible. Using <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any"/> within the content model for observation we can integrate all the additional content models for person, location, weather etc, and then decide on naming namespaces at a later date. But then as we progress, we are probably going to want to tie down the content more. The idea behind xs:anyType was to allow an author to define a more advanced weather definition than the one we offer by default, without interferring with the actual astroXML schema. Besides, as far as development goes, I was somewhat aghast to discover that XMLSpy will validate simpleTypes using the xs:anyType method above but *not* complexTypes!! XSV does validate both types. Tom |