Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Wildcards in SML schema >Thread Next - Re: Wildcards in SML schema Re: Wildcards in SML schemaTo: NULL Date: 6/6/2007 1:48:00 AM
On 6 Jun, 04:46, Grant Robertson <b...@bogus.invalid> wrote:
> If I use the 'any' element in my schema to allow elements from another
> schema to be used in instance documents based on my schema, is there a
> way to force that the contents of that element must be an entire,
> complete instance document for that other schema?
>
> Let's say I have the following schema:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> <xs:element name="BogusElement" type="BogusType"/>
> <xs:complexType name="BogusType">
> <xs:sequence>
> <xs:any namespace="http://www.w3.org/1999/xhtml"/>
> </xs:sequence>
> </xs:complexType>
> </xs:schema>
This would allow any global element from www.w3.org/1999/xhtml/.
> <?xml version="1.0" encoding="UTF-8"?>
> <BogusElement
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="Untitled1.xsd"
> xmlns:xhtml="http://www.w3.org/1999/xhtml">
> <xhtml:strong>Bolded Text.</xhtml:strong>
> </BogusElement>
>
> be a valid document under the above schema?
Yes.
> How can I make it so that the contents of the BogusElement element in the
> instance document must be a complete XHTML document in order to be valid?
> Or would I just have to make that a verbal rule, not expressed in the
> schema?
You could try the following schema approach...
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="BogusElement" type="BogusType"/>
<xs:complexType name="BogusType">
<xs:sequence>
<xs:element xmlns:xhtml="http://www.w3.org/1999/xhtml"
ref="xhtml:xthml"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
> To complicate things further: Let's say I wanted that element to contain
> only one of a list of valid, complete documents such as either a complete
> html document OR a complete XHTML document OR a complete DocBook
> document, all with headers. How would I do that?
Including an HTML document obviously has the problem that an HTML
document is not typically well-formed XML. But we can leave that
aside for the moment!
Also, I'm not sure of the valid set of DocBook schemas.
Given that, your schema could look something like:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="BogusElement" type="BogusType"/>
<xs:complexType name="BogusType">
<xs:choice> <!--Changed from sequence-->
<xs:element xmlns:xhtml="http://www.w3.org/1999/xhtml"
ref="xhtml:xthml"/>
<xs:element xmlns:docbook="http://docbook"
ref="docbook:docbook"/>
</xs:choice>
</xs:complexType>
</xs:schema>
HTH,
Pete.
--
=============================================
Pete Cordell
Codalogic Ltd
for XML Schema to C++ data binding visit
http://www.codalogic.com/lmx/
=============================================
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
