Re: Recursive XSD Design

Thanks Michael.

I've redesigned the schema. It's now quite simple. All it took was to
realise that I had overloaded the 'key' element to much.

Splitting out the key element and giving its different meanings different
element names not only makes it simpler but the xsd drops out easily.

The xml now looks like this

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2010 rel. 2 (http://www.altova.com) by NLeaton
(investec) -->
<messages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\temp\test.xsd">
    <message name="trade">
        <composed name="trade" type="trade">
            <reference name="trade" reference="trade">
                <id name="TRDNBR" system="FRONT"
instance="PROD">1001917</id>
                <id name=" CONTRACT_TRDNBR" system="FRONT"
instance="PROD">1001917</id>
            </reference>
            <reference name="instrument" reference=" instrument">
                <id name=" INSID" system="FRONT"
instance="PROD">DEM/BND/128000</id>
                <id name=" INSADDR" system="FRONT"
instance="PROD">125426</id>
                <id name=" EXTERN_ID1" system="FRONT" instance="PROD">
ext128k</id>
            </reference>
            <value name="acquire_day"
representation="isodate">1998-03-12</value>
            <reference name="acquirer" type=" party">
                <id name=" PTYID" system="FRONT" instance="PROD">Bond Nat
Desk</id>
            </reference>
            <reference name="currency" reference=" instrument">
                <id name=" INSID" system="FRONT" instance="PROD">DEM</id>
                <id name=" EXTERN_ID1" system="FRONT"
instance="PROD">23</id>
            </reference>
            <value name="value_day"
representation="isodate">1999-03-12</value>
            <value name="time" representation="isodatetime">1998-03-10
12:29:06</value>
            <value name="quantity">5</value>
            <value name="price" representation="percentage">99.78</value>
            <value name="premium">-5205389</value>
            <value name="fee">100</value>
            <reference name="status" reference="status">
                <id name="STATUS" system="FRONT" instance="PROD">FO
Confirmed</id>
            </reference>
            <reference name="counterparty" reference=" party">
                <id name=" PTYID" system="FRONT"
instance="PROD">Investor</id>
            </reference>
            <reference name="trader" reference=" user">
                <id name=" USERID" system="FRONT" instance="PROD">ATLAS</id>
            </reference>
            <value name="type">Normal</value>
            <reference name="broker" reference=" party">
                <id name=" PTYID" system="FRONT" instance="PROD">Broker
A</id>
            </reference>
            <reference name="document_type" reference="ISDA">
                <id name="ISDA" system="FRONT" instance="PROD">Standard
Document</id>
            </reference>
            <value name="text1">TRD17</value>
            <value name="execution_time"
representation="isodatetime">1998-03-10 12:29:06</value>
            <value name="break_date"
representation="isodate">1999-03-10</value>
            <composed name="leg" type="leg">
                <value name="coupon"
representation="percentage">5.00</value>
                <value name="maturity"
representation="isodate">2010-01-01</value>
            </composed>
        </composed>
    </message>
</messages>

and the xsd is this

<?xml version="1.0" encoding="UTF-8"?>
<!--W3C Schema generated by XMLSpy v2010 rel. 2 (http://www.altova.com)-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="MessagesType">
        <xs:sequence>
            <xs:element name="message" type="MessageType"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="ValueType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="representation" type="xs:string"/>
                <xs:attribute name="name" type="xs:string" use="required"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    <xs:complexType name="IdType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="system" type="xs:string"
use="required"/>
                <xs:attribute name="name" type="xs:string" use="required"/>
                <xs:attribute name="instance" type="xs:string"
use="required"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    <xs:complexType name="ReferenceType">
        <xs:sequence>
            <xs:element name="id" type="IdType" minOccurs="1"
maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="type" type="xs:string"/>
        <xs:attribute name="reference" type="xs:string"/>
        <xs:attribute name="name" type="xs:string" use="required"/>
    </xs:complexType>
    <xs:complexType name="ComposedType">
        <xs:sequence minOccurs="1" maxOccurs="unbounded">
            <xs:choice>
                <xs:element name="reference" type="ReferenceType"/>
                <xs:element name="composed" type="ComposedType"/>
                <xs:element name="value" type="ValueType"/>
            </xs:choice>
        </xs:sequence>
        <xs:attribute name="type" type="xs:string" use="required"/>
        <xs:attribute name="name" type="xs:string" use="required"/>
    </xs:complexType>
    <xs:complexType name="MessageType">
        <xs:sequence>
            <xs:element name="composed" type="ComposedType"/>
        </xs:sequence>
        <xs:attribute name="name" type="xs:string" use="required"/>
    </xs:complexType>
    <xs:element name="messages" type="MessagesType"/>
</xs:schema>

Changes are now easy to make to the schema.

A classic example of where you get fixated on a problem and cannot see the
wood for the trees.

Thanks for the help

Nick

On Mon, Mar 22, 2010 at 3:16 PM, Michael Kay <mike@saxonica.com> wrote:

>  The interesting thing is that the usual reason people do
>
> <field name="N" value="V"/>
>
> rather than
>
> <N>V</N>
>
> is that they DON'T want to be constrained a schema; they somehow feel that
> the "generic" (verbose) form is more extensible than the concise form.
>
> You can use the generic design if you like. Personally I really don't see
> the point of it. XSD 1.0 doesn't support it, in the sense that it doesn't
> allow the type of V to depend on the value of N. XSD 1.1 has a feature
> called "conditional type assignment" that fills this gap. But I still think
> it's a curious way to design your XML.
>
>
> Regards,
>
> Michael Kay
> http://www.saxonica.com/
> http://twitter.com/michaelhkay
>
>  ------------------------------
> *From:* xmlschema-dev-request@w3.org [mailto:xmlschema-dev-request@w3.org]
> *On Behalf Of *nickle@gmail.com
> *Sent:* 22 March 2010 11:42
> *To:* xmlschema-dev@w3.org
> *Subject:* Recursive XSD Design
>
> I'm having trouble creating an XSD for some xml.
>
> A bit of background might help. The xml is for messaging. In particular,
> the message
> is designed to be simple, and designed to be cross referenced easily. At
> its heart
> is a recursive key value set up.
>
> Simple Key values are like this.
>
> <key name="quantity">5</key>
> <key name="price" representation="percentage">99.78</key>
>
> There is an optional representation attribute where the infromation
> could be represented in two different forms.
>
> Reference Key Values are like this
>
> <key name="currency" reference="instrument">
> <id name=" INSID" system="XXXX" instance="PROD">DEM</id>
> <id name=" EXTERN_ID1" system="XXXX" instance="PROD"> ext128k</id>
> </key>
>
> This form is used for foreign key references or for references to
> enumerations.
> The cross reference service will select out all keys with an attribute of
> reference.
> It will then get all possible ids for that reference, and add in additional
> id
> fields, and replace that sub element with the new version.
>
> ie ".//key[@reference]" as an Xpath can get all the enumerations and
> references
> from the xml
>
> Lastly there is a the recursive structure. Here the value part of the key
> value,
> can be a key value itself.
>
> <key name="trade" type="trade">
> <key name="value_day">1999-03-12</key>
> <key name="quantity">5</key>
> <key name="leg" type="leg">
> <key name="rate">5.00</key>
> <key name="period">3m</key>
> <key name="cashflows" type="cashflows">
> <key name="cashflow">10</key>
> <key name="cashflow">20</key>
> </key>
> </key>
> </key>
>
> Now, I'm having real trouble creating an XSD for this structure.
>
> Can anyone help?
>
> Thanks
>
> Nick
>
>


-- 
Nick

Received on Tuesday, 23 March 2010 15:05:07 UTC