XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] RE: [XSD question] Does ref'ing to the same globalelement declaration multiple times violate the Don't Repeat Yourself principle?

Hi Roger,
   Great thread.

Little observation from my side.

In the context of examples, illustrated within this thread, I think the syntax <xs:group ref=".."/> has advantage over writing via <xs:element ref=".."/>, is that <xs:group ref=".." solves the problem of XSD schema specifying multiple root elements (I always, wanted to solve that problem with pure XSD syntax, and this thread gave me an insight).

On Thu, Jan 6, 2022 at 8:12 PM Roger L Costello <costello@mitre.org> wrote:
Hi Folks,

Thank you for your responses. Very good, ref'ing multiple times to a global element declaration does not violate DRY.

Below I have slightly modified the XML Schema. I created an xs:group and placed the ref's to Title and Publisher inside the xs:group. Now the Book and Magazine elements ref to the xs:group. In the previous XML Schema design there were two ref's to Title and two ref's to Publisher:

<xs:element ref="Title" />
<xs:element ref="Title" />
<xs:element ref="Publisher" />
<xs:element ref="Publisher" />

In the new design there is only one ref to Title and one ref to Publisher (the ref's are inside xs:group). But now there are two ref's to the xs:group

<xs:group ref="Title-and-Publisher" />
<xs:group ref="Title-and-Publisher" />

In the previous design there were four ref's:

<xs:element ref="Title" />
<xs:element ref="Title" />
<xs:element ref="Publisher" />
<xs:element ref="Publisher" />

In the new design there are also four ref's:

<xs:group ref="Title-and-Publisher" />
<xs:group ref="Title-and-Publisher" />
<xs:element ref="Title" />
<xs:element ref="Publisher" />

Suppose Book and Magazine have three common elements: Title, Publisher, and Author. In the old design there would be six ref's:

<xs:element ref="Title" />
<xs:element ref="Title" />
<xs:element ref="Publisher" />
<xs:element ref="Publisher" />
<xs:element ref="Author" />
<xs:element ref="Author" />

In the new design there would be five ref's:

<xs:group ref="Title-and-Publisher-and-Author" />
<xs:group ref="Title-and-Publisher-and-Author" />
<xs:element ref="Title" />
<xs:element ref="Publisher" />
<xs:element ref="Author" />

You have stated that ref's do not violate DRY. Here we see an opportunity to reduce the number of ref's by using xs:group. Is a design that uses less ref's more DRY-compliant than a design that uses more ref's?  /Roger
----------------------------------------------
<xs:element name="Bookstore">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Book" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:sequence>
                        <xs:group ref="Title-and-Publisher" />
                        ...
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="Magazine" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:sequence>
                        <xs:group ref="Title-and-Publisher" />
                        ...
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:group name="Title-and-Publisher">
    <xs:sequence>
        <xs:element ref="Title" />
        <xs:element ref="Publisher" />
    </xs:sequence>
</xs:group>

<xs:element name="Title" type="xs:string" />
<xs:element name="Publisher" type="xs:string" />


--
Regards,
Mukul Gandhi


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS