W3C home > Mailing lists > Public > xmlschema-dev@w3.org > June 2001

RE: Xml Schema Blues

From: Tom Wason <wason@mindspring.com>
Date: Mon, 11 Jun 2001 10:09:48 -0400
To: "Whitwell, Martyn" <martyn.whitwell@ic.ac.uk>, <xmlschema-dev@w3.org>
Message-ID: <NEBBJIDAALNJAOPHOLJJKEHDEOAA.wason@mindspring.com>
Martyn--

You may want to try this approach:

<?xml version="1.0" encoding="UTF-8"?>
<paragraph xmlns="paragraph"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:schemaLocation="paragraph paragraph.xsd">
Here is some <bold>bold</bold> text, whereas this text is in
<bold><italic>bold italics</italic></bold>. This text does not have any
underlined bits, but it could have.
</paragraph>

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="paragraph" targetNamespace="paragraph"
xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
elementFormDefault="qualified">
	<xsd:element name="paragraph" type="paraType"/>
	<xsd:element name="bold" type="paraType"/>
	<xsd:element name="italic" type="paraType"/>
	<xsd:element name="underlined" type="paraType"/>
	<xsd:complexType name="paraType" mixed="true">
		<xsd:choice minOccurs="0" maxOccurs="unbounded">
			<xsd:element ref="bold"/>
			<xsd:element ref="italic"/>
			<xsd:element ref="underlined"/>
		</xsd:choice>
	</xsd:complexType>
</xsd:schema>

I've used the same complexType for all of the elements.  You may want to
tailor this a bit.  I haave validataed this in XML Spy 3.5 against your
sample, which I included above the schema.  I modified your sample to
include a  namespace and so forth.

--Tom



Thomas D. Wason
+1 919.839.8187
wason@mindspring.com
http://www.twason.com
1421 Park Drive
Raleigh, North Carolina 27605 USA

-----Original Message-----
From: xmlschema-dev-request@w3.org
[mailto:xmlschema-dev-request@w3.org]On Behalf Of Whitwell, Martyn
Sent: Monday, June 11, 2001 5:36 AM
To: 'xmlschema-dev@w3.org'
Subject: Xml Schema Blues


Hi there,

I'm trying to build an xml schema to describe pages on Imperial College's
website (www.ic.ac.uk). I've been using XML Spy to help automate the process
of building the schema. My problem lies when I try to define a complex type
to encompass several different elements which may or may not be present,
e.g.

<paragraph>
Here is some <bold>bold</bold> text, whereas this text is in
<bold><italic>bold italics</italic></bold>. This text does not have any
underlined bits, but it could have.
</paragraph>


After much work, I found this sort of xml document could be described by the
schema:

<xsd:complexType name="typeEmpText" mixed="true">
  <xsd:complexContent>
    <xsd:extension base="xsd:string">
      <xsd:sequence>
        <xsd:element ref="bold" minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element ref="italic" minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element ref="underline" minOccurs="0" maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:extension>
  </xsd:complexContent>
</xsd:complexType>

<xsd:element name="paragraph" type="typeEmpText"/>
<xsd:element name="bold" type="typeEmpText"/>
<xsd:element name="italic" type="typeEmpText"/>
<xsd:element name="underline" type="typeEmpText"/>


This schema successfully validated the xml document I had prepared. However,
I soon found that XML Spy recoded the complexType typeEmpText "more
efficiently", producing:

<xsd:complexType name="typeEmpText" mixed="true">
  <xsd:simpleContent>
    <xsd:extension base="xsd:string"/>
  </xsd:simpleContent>
</xsd:complexType>

But, this new coding no longer validates my xml document! I guess there must
be something wrong with the complexType I defined (indeed, this is most
likely as I've not written schemas or DTDs before) - but I can't see the
problem? The complexType is deliberately slightly recursive to allow for any
amount of sub-elements and sub-sub-elements - is this strictly allowed? Or
is Xml Spy in error for believing that my complexType is wrong?

All help would be very much welcomed.

Thanks,

Martyn Whitwell.
martyn.whitwell@ic.ac.uk
Centre for Computing Services, Imperial College, London, UK.
Received on Monday, 11 June 2001 10:11:42 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:21 GMT