"Migration" from IDREFS to an XML-Schema expression

Discussion in 'XML' started by Rabe, Aug 13, 2004.

  1. Rabe

    Rabe Guest

    Hi all,

    here a little brain-twister (starting to spoil my weekend
    if I do not find a solution ... ;-) )

    What I want to do is to find a XML-Schema expression that builds
    a grammar for the following XML document (fragment):

    <grouping_document>
    <app_list>
    <app id="id1">Program 1</app>
    <app id="id2">Program 2</app>
    <app id="id3">Program 3</app>
    <!-- etc. -->
    </app_list>

    <grouping app_ref="id1 id3">
    <!-- stuff for the referenced apps -->
    </grouping>

    <grouping app_ref="id2">
    <!-- stuff for the referenced apps -->
    </grouping>
    </grouping_document>


    The <grouping_document> describes some information that may be valid for
    one or more applications. So it starts with a list of application definitions
    whereas the key issue is that only the listed ids are allowed to appear as
    values of attribute app_ref in the element <grouping>.

    A valid DTD for this is

    <!DOCTYPE grouping_document [
    <!ELEMENT grouping_document ( app_list, grouping+ )>

    <!ELEMENT app_list (app+)>
    <!ELEMENT app (#PCDATA)>
    <!ATTLIST app id ID #REQUIRED>

    <!-- etc. -->

    <!ELEMENT grouping (grouping_element+)>
    <!ATTLIST grouping app_ref IDREFS #REQUIRED>

    <!-- etc. -->
    ]>


    But how to express these ID/IDREFS expressions in suitable in XML-Schema syntax?
    (I do not have a problem with the standard key/keyref expressions. Where I'm
    failing is the formulation of a list of references as value of a simple attribute.)

    Here's what I have tried:

    <xsd:complexType name="GroupingType">
    <xsd:sequence>
    <xsd:element name="app_list" type="AppListType">
    <xsd:key name="AppKey">
    <xsd:selector xpath="app"/>
    <xsd:field xpath="@id"/>
    </xsd:key>
    </xsd:element>
    <xsd:element name="grouping" type="GroupingType"/>
    </xsd:sequence>
    </xsd:complexType>

    <!-- etc. -->

    <complexType name="GroupingType">
    <sequence>
    <element name="grouping_element">
    <!-- etc. -->
    </element>
    </sequence>

    <attribute name="id">
    <simpleType name="AppIdList">
    <list itemType="string"/>
    </simpleType>
    <keyref name="aref" refer="jrn:AppKey">
    <field xpath="@app_id"/>
    </keyref>
    </attribute>
    </complexType>


    It's wrong, I know ...

    But perhaps someone has a little tip for me?

    Many thanks for your efforts!
    Rabe
    Rabe, Aug 13, 2004
    #1
    1. Advertising

  2. Rabe wrote:


    > here a little brain-twister (starting to spoil my weekend
    > if I do not find a solution ... ;-) )
    >
    > What I want to do is to find a XML-Schema expression that builds
    > a grammar for the following XML document (fragment):
    >
    > <grouping_document>
    > <app_list>
    > <app id="id1">Program 1</app>
    > <app id="id2">Program 2</app>
    > <app id="id3">Program 3</app>
    > <!-- etc. -->
    > </app_list>
    >
    > <grouping app_ref="id1 id3">
    > <!-- stuff for the referenced apps -->
    > </grouping>
    >
    > <grouping app_ref="id2">
    > <!-- stuff for the referenced apps -->
    > </grouping>
    > </grouping_document>
    >
    >
    > The <grouping_document> describes some information that may be valid for
    > one or more applications. So it starts with a list of application definitions
    > whereas the key issue is that only the listed ids are allowed to appear as
    > values of attribute app_ref in the element <grouping>.
    >
    > A valid DTD for this is
    >
    > <!DOCTYPE grouping_document [
    > <!ELEMENT grouping_document ( app_list, grouping+ )>
    >
    > <!ELEMENT app_list (app+)>
    > <!ELEMENT app (#PCDATA)>
    > <!ATTLIST app id ID #REQUIRED>
    >
    > <!-- etc. -->
    >
    > <!ELEMENT grouping (grouping_element+)>
    > <!ATTLIST grouping app_ref IDREFS #REQUIRED>


    But a W3C XML schema allows you to define attributes of type xs:ID as
    well as of type xs:IDREFS, see
    http://www.w3.org/TR/xmlschema-2/#built-in-datatypes
    http://www.w3.org/TR/xmlschema-2/#ID
    http://www.w3.org/TR/xmlschema-2/#IDREFS
    so you can simply type your attributes as you have typed them in the DTD.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Aug 14, 2004
    #2
    1. Advertising

  3. Rabe

    R. B. Guest

    Hi,

    thanks for your answer, I think it would (will!) work. (I know that
    these types are valid in schema definitions too but I actually didn't
    have the idea to use them ... :)) )

    But nevertheless there must be a solution to express ID/IDREFS in schema
    syntax too, don't you think so?

    As far as I know ID declarations bring up the problem that they are
    global all over the document. So if I have a lot of ID declarations in
    different elements how can I be sure that I'm referencing always the
    right type of id?

    When I expand my example with a list

    <resource_list>
    <resource id="res_id1"/>
    <resource id="res_id2"/>
    <resource id="res_id3"/>
    </resource_list>

    I will be able to reference a pretended application "res_id1" e.g.

    <grouping app_ref="id1 res_id1">
    <!-- stuff for the referenced apps -->
    </grouping>

    which is syntactically correct but semantically nonsense ...

    Hmm ...

    But your tip helped me a lot - I was already thinking about changing the
    structure of my instance document ...

    Bye Rabe



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    R. B., Aug 14, 2004
    #3
  4. R. B. wrote:


    > thanks for your answer, I think it would (will!) work. (I know that
    > these types are valid in schema definitions too but I actually didn't
    > have the idea to use them ... :)) )
    >
    > But nevertheless there must be a solution to express ID/IDREFS in schema
    > syntax too, don't you think so?


    I told you to use the xs:ID and xs:IDREFS types, those are schema types,
    so I am not sure why you ask for schema syntax, if you use
    <xs:attribute name="id" type="xs:ID" />
    then that is schema syntax and that is all I suggested to do.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Aug 15, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,493
    Markus
    Nov 23, 2005
  2. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,165
    Stanimir Stamenkov
    Apr 25, 2005
  3. Mark
    Replies:
    6
    Views:
    424
  4. Replies:
    0
    Views:
    249
  5. Boni Satani
    Replies:
    0
    Views:
    141
    Boni Satani
    Jan 9, 2014
Loading...

Share This Page