Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: Repeating elements with fixed attribute values

From: "King, Jeffrey (Mission Systems)" <Jeff.King@---.--->
To: <xmlschema-dev@--.--->
Date: 1/4/2008 4:09:00 AM
Thank you very much for your insights.  I am surprised to find that this
is not allowed in XML Schema 1.0.  The data that I am representing is
message data.  There are many messages each with words and fields (the
message itself being represented by the "root" element in my example).
If I use an approach that assumes the structure is in the element names,
then every message will have it's own set of element names and any
meaning a particular element has comes only from it's relative postion
in the document.  I thought that the approach I took below was a good
one.  However, I am wondering that if XML Schema 1.0 does not support
it, then maybe it's trying to tell me it's not good approach.  Are there
any reasons (other than XML Schema 1.0 does not support it) why using
the design I presented below is poor?

Thanks again.

Jeffrey

-----Original Message-----
From: Andrew Welch [mailto:andrew.j.welch@g...] 
Sent: Friday, January 04, 2008 10:41 AM
To: King, Jeffrey (Mission Systems)
Cc: xmlschema-dev@w...
Subject: Re: Repeating elements with fixed attribute values

On 04/01/2008, King, Jeffrey (Mission Systems) <Jeff.King@n...>
wrote:
> I have an xml document similar to this:
>
> <root>
>   <word name="one">
>     <field name="field1" number="1">any string here</field>
>     <field name="field2" number="2">any string here</field>
>     <field name="field3" number="3">any string here</field>
>     ...
>   </word>
>   <word name="two">
>     <field name="field4" number="4">any string here</field>
>     <field name="field5" number="5">any string here</field>
>     <field name="field6" number="6">any string here</field>
>     ...
>   </word>
> </root>
>
> The attributes have fixed values.  I am struggling to create a schema 
> for this.

If you mean you want to ensure that @number="1" if @name="field1" =
and so
on, then that's a "co-occurrence constraint", which isn't possible to
define in XML Schema.

It will be possible in XML Schema 1.1 (check out Saxon's schema
processor), but in the mean time you'll need to do the check in another
language, like Schematron or RelaxNG.

If you're feeling brave you could do the check using xchecker - the
schema would look something like this (note the <xck:check> element):

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xck="http://xchecker.sf.net/"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">

    <xs:annotation>
        <xs:appinfo>
            <xck:check>//field[@number eq translate(@name, 'field',
'')]</xck:check>
        </xs:appinfo>
    </xs:annotation>

    <xs:element name="root" type="root"/>
    <xs:element name="word" type="word"/>
    <xs:element name="field" type="field"/>

    <xs:complexType name="root">
        <xs:sequence>
            <xs:element ref="word" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="word">
        <xs:sequence>
            <xs:element ref="field" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="name" use="required"
type="non-empty-string"/>
    </xs:complexType>

    <xs:complexType name="field">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="name" use="required"
type="non-empty-string"/>
                <xs:attribute name="number" use="required"
type="xs:integer"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:simpleType name="non-empty-string">
        <xs:restriction base="xs:string">
            <xs:minLength value="1"/>
        </xs:restriction>
    </xs:simpleType>   =09

</xs:schema>


More here: http://xchecker.sourceforge.net/


cheers
--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

From Jeff.King@n... Fri Jan 04 17:34:25 2008
Received: from lisa.w3.org ([128.30.52.41])
	by frink.w3.org with esmtp (Exim 4.63)
	(envelope-from <Jeff.King@


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent