Altova Mailing List Archives>Archive Index >xmlschema-dev Archive Home >Recent entries >Thread Prev - Re: Defining recursive elements? >Thread Next - RE: Defining recursive elements? Re: Defining recursive elements?To: xmlschema-dev@--.--- Date: 5/17/2007 11:51:00 AM
Ah, look at that! Thanks for the feedback.
I reconstructed the xsd to use a custom type:
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="component">
<xsd:sequence>
<xsd:element name="component" type="component" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="type">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{3}"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="serial">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{10}"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
<xsd:element name="adapter">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="header"/>
<xsd:element name="components">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="component" type="component"
minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:unique name="componentTypeAndSerial">
<xsd:selector xpath=".//component"/>
<xsd:field xpath="@type"/>
<xsd:field xpath="@serial"/>
</xsd:unique>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
This seems to work much better.
- Todd.
On 5/17/07, Andrew Welch <andrew.j.welch@g...> wrote:
> On 5/17/07, Todd Moon <tmrfcm@g...> wrote:
> >
> > (Forgive me if this is a duplicate, Gmail hiccuped for 5 minutes after
> > I hit send. I don't see my message in the Sent folder though)
> >
> > I've been fleshing out my schema. I renamed "part" to "component", and
> > added some unique and pattern validation. ("type" and "serial"
> > together must be unique across all components.)
> >
> > I would appreciate some criticism of my schema's overall construction.
> > Here it is:
> >
> > <?xml version="1.0" encoding="utf-8"?>
> > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> > <xsd:element name="header"/>
> > <xsd:element name="components">
> > <xsd:complexType>
> > <xsd:sequence>
> > <xsd:element ref="component" minOccurs="0" maxOccurs="unbounded"/>
> > </xsd:sequence>
> > </xsd:complexType>
> > <xsd:unique name="componentTypeAndSerial">
> > <xsd:selector xpath=".//component"/>
> > <xsd:field xpath="@type"/>
> > <xsd:field xpath="@serial"/>
> > </xsd:unique>
> > </xsd:element>
> > <xsd:element name="component">
> > <xsd:complexType>
> > <xsd:sequence>
> > <xsd:element ref="component" minOccurs="0" maxOccurs="unbounded"/>
> > </xsd:sequence>
> > <xsd:attribute ref="type"/>
> > <xsd:attribute ref="serial"/>
> > </xsd:complexType>
> > </xsd:element>
> > <xsd:attribute name="serial">
> > <xsd:simpleType>
> > <xsd:restriction base="xsd:string">
> > <xsd:pattern value="\d{10}"/>
> > </xsd:restriction>
> > </xsd:simpleType>
> > </xsd:attribute>
> > <xsd:attribute name="type">
> > <xsd:simpleType>
> > <xsd:restriction base="xsd:string">
> > <xsd:pattern value="\d{3}"/>
> > </xsd:restriction>
> > </xsd:simpleType>
> > </xsd:attribute>
> > <xsd:element name="adapter">
> > <xsd:complexType>
> > <xsd:sequence>
> > <xsd:element ref="header"/>
> > <xsd:element ref="components"/>
> > </xsd:sequence>
> > </xsd:complexType>
> > </xsd:element>
> > </xsd:schema>
> >
> > Here is an example of a valid document:
> >
> > <adapter>
> > <header>
> > </header>
> > <components>
> > <component type="735" serial="0000000001">
> > <component type="736" serial="0000000001"/>
> > <component type="736" serial="0000000002"/>
> > <component type="740" serial="0000000003"/>
> > </component>
> > <component type="735" serial="0000000002">
> > </component>
> > <component type="735" serial="0000000003"/>
> > </components>
> > </adapter>
>
> With global definitions some documents will be valid that you might
> not want, for example an XML document of just <header/> would validate
> using that schema.
>
From boris@k... Thu May 17 20:25:40 2007
Received: from maggie.w3.org ([193.51.208.68])
by frink.w3.org with esmtp (Exim 4.50)
id 1HomXc-0003ta-8Q
for xmlschema-dev@listhub. | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
