XML-Schema and comlpexTypes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jakob Møbjerg Nielsen

    XML-Schema and comlpexTypes

    Hi

    Is it possible to represent a linked list in XML-Schema. Somthing like:

    <xsd:complexTyp e name="Llist" >
    <xsd:sequence >
    <xsd:element name="content" type="xsd:strin g"/>
    <xsd:element name="next" type="Llist"/>
    </xsd:sequence>
    </xsd:complexType >

    --
    Jakob Møbjerg Nielsen | "Nine-tenths of the universe is the
    jakob@dataloger .dk | knowledge of the position and direction
    http://www.jakobnielsen.dk/ | of everything in the other tenth."
    | -- Terry Pratchett, Thief of Time



  • Martin Honnen

    #2
    Re: XML-Schema and comlpexTypes



    Jakob Møbjerg Nielsen wrote:
    [color=blue]
    > Is it possible to represent a linked list in XML-Schema. Somthing like:
    >
    > <xsd:complexTyp e name="Llist" >
    > <xsd:sequence >
    > <xsd:element name="content" type="xsd:strin g"/>
    > <xsd:element name="next" type="Llist"/>
    > </xsd:sequence>
    > </xsd:complexType >[/color]

    Why not, the only flaw with your scheme is that I see no way to
    terminate the list so I think

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:complexTy pe name="Llist" >
    <xs:sequence>
    <xs:element name="content" type="xsd:strin g"/>
    <xs:element name="next" type="Llist" minOccurs="0" maxOccurs="1" />
    </xs:sequence>
    </xs:complexType>

    <xs:element name="list" type="Llist" />

    </xs:schema>

    is better.
    --

    Martin Honnen


    Comment

    • Jakob Møbjerg Nielsen

      #3
      Re: XML-Schema and comlpexTypes

      Martin Honnen wrote:[color=blue]
      > Why not, the only flaw with your scheme is that I see no way to
      > terminate the list so I think[/color]
      [snip][color=blue]
      > is better.[/color]

      Thanks, but I still have my doubts wether it is legal or not to do
      recursion in XML-Schema. I can't find anything about it in the
      recommendation.

      --
      Jakob Møbjerg Nielsen | "Nine-tenths of the universe is the
      jakob@dataloger .dk | knowledge of the position and direction
      http://www.jakobnielsen.dk/ | of everything in the other tenth."
      | -- Terry Pratchett, Thief of Time


      Comment

      • Martin Honnen

        #4
        Re: XML-Schema and comlpexTypes



        Jakob Møbjerg Nielsen wrote:
        [color=blue]
        > Thanks, but I still have my doubts wether it is legal or not to do
        > recursion in XML-Schema. I can't find anything about it in the
        > recommendation.[/color]

        Recursion is allowed in XML documents and with XML schemas, why
        shouldn't it. Try that example schema with any parser validating against
        XML schema and I don't think you will get any errors.


        --

        Martin Honnen


        Comment

        • Jakob Møbjerg Nielsen

          #5
          Re: XML-Schema and comlpexTypes

          Martin Honnen wrote:[color=blue]
          > Recursion is allowed in XML documents and with XML schemas, why
          > shouldn't it. Try that example schema with any parser validating
          > against XML schema and I don't think you will get any errors.[/color]

          Thanks again... I'm convinced, but I'm having just a *bit* trouble in
          seeing how it will look in "straight" XML. My guess is:

          <list>
          <Llist>
          <content>El.1 </content>
          <Llist>
          <content>El.2 </content>
          <Llist>
          <content>El.3 </content>
          <Llist>
          <content>El.4 </content>
          </Llist>
          </Llist>
          </Llist>
          </Llist>
          </list>

          Is that all wrong? It looks kind of ugly, but if that's the only way...
          :-)

          --
          Jakob Møbjerg Nielsen | "Nine-tenths of the universe is the
          jakob@dataloger .dk | knowledge of the position and direction
          http://www.jakobnielsen.dk/ | of everything in the other tenth."
          | -- Terry Pratchett, Thief of Time


          Comment

          • Jakob Møbjerg Nielsen

            #6
            Re: XML-Schema and comlpexTypes

            Martin Honnen wrote:[color=blue]
            > Recursion is allowed in XML documents and with XML schemas, why
            > shouldn't it. Try that example schema with any parser validating
            > against XML schema and I don't think you will get any errors.[/color]

            I just found out that Schemas like
            http://www.w3.org/2001/03/XMLSchema/...ry-nn-list.xsd (which
            contains an example of how W3 would implement a linked list), cannot be
            viewed with Mozilla. It only displays the documentation elements. IE
            shows everything, though. Why, Mozilla... why? :-)

            --
            Jakob Møbjerg Nielsen | "Nine-tenths of the universe is the
            jakob@dataloger .dk | knowledge of the position and direction
            http://www.jakobnielsen.dk/ | of everything in the other tenth."
            | -- Terry Pratchett, Thief of Time


            Comment

            • Martin Honnen

              #7
              Re: XML-Schema and comlpexTypes



              Jakob Møbjerg Nielsen wrote:
              [color=blue]
              > Martin Honnen wrote:
              >[color=green]
              >>Recursion is allowed in XML documents and with XML schemas, why
              >>shouldn't it. Try that example schema with any parser validating
              >>against XML schema and I don't think you will get any errors.[/color]
              >
              >
              > Thanks again... I'm convinced, but I'm having just a *bit* trouble in
              > seeing how it will look in "straight" XML. My guess is:
              >
              > <list>
              > <Llist>
              > <content>El.1 </content>
              > <Llist>
              > <content>El.2 </content>
              > <Llist>
              > <content>El.3 </content>
              > <Llist>
              > <content>El.4 </content>
              > </Llist>
              > </Llist>
              > </Llist>
              > </Llist>
              > </list>
              >
              > Is that all wrong? It looks kind of ugly, but if that's the only way...[/color]

              Your schema I improved is

              <?xml version="1.0" encoding="UTF-8"?>
              <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

              <xs:complexTy pe name="Llist" >
              <xs:sequence>
              <xs:element name="content" type="xsd:strin g"/>
              <xs:element name="next" type="Llist" minOccurs="0" maxOccurs="1" />

              An instance is

              <?xml version="1.0" encoding="iso-8859-1"?>
              <list xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
              xsi:noNamespace SchemaLocation= "test20031209Xs d.xml">
              <content>1</content>
              <next>
              <content>2</content>
              <next>
              <content>3</content>
              </next>
              </next>
              </list>
              </xs:sequence>
              </xs:complexType>

              <xs:element name="list" type="Llist" />

              </xs:schema>

              --

              Martin Honnen


              Comment

              • Martin Honnen

                #8
                Re: XML-Schema and comlpexTypes



                Jakob Møbjerg Nielsen wrote:
                [color=blue]
                > Martin Honnen wrote:
                >[color=green]
                >>Recursion is allowed in XML documents and with XML schemas, why
                >>shouldn't it. Try that example schema with any parser validating
                >>against XML schema and I don't think you will get any errors.[/color]
                >
                >
                > I just found out that Schemas like
                > http://www.w3.org/2001/03/XMLSchema/...ry-nn-list.xsd (which
                > contains an example of how W3 would implement a linked list), cannot be
                > viewed with Mozilla. It only displays the documentation elements. IE
                > shows everything, though. Why, Mozilla... why? :-)[/color]

                Well, IE(5/6)/Win applies an XSLT default stylesheet to the XML which
                renders a clickable tree with dynamic HTML. IE doesn't recognize that
                there are any XHTML elements in the document as IE doesn't support XHTML.
                Mozilla however supports XHTML and recognizes that there are elements
                with the XHTML namespace http://www.w3.org/1999/xhtml in the document
                and therefore tries to render the XML file as it is, meaning it applies
                the XHTML rendering rules to the XHTML elements and CSS default rules to
                the unknown xs:tagname elements. That has not the result that you want
                but is a possible approach which allows you to write mixed namespace XML
                documents using XHTML elements and style them with CSS and have them
                rendered by Mozilla.

                --

                Martin Honnen


                Comment

                • Patrick TJ McPhee

                  #9
                  Re: XML-Schema and comlpexTypes

                  In article <br4feg$qp8$1@s unsite.dk>,
                  Jakob Møbjerg Nielsen <jakob@dataloge r.dk> wrote:

                  % Is it possible to represent a linked list in XML-Schema. Somthing like:
                  %
                  % <xsd:complexTyp e name="Llist" >
                  % <xsd:sequence >
                  % <xsd:element name="content" type="xsd:strin g"/>
                  % <xsd:element name="next" type="Llist"/>
                  % </xsd:sequence>
                  % </xsd:complexType >

                  I wouldn't call this a linked-list representation. After all, `next'
                  embeds the next element of the list as content. I'd go so far as to
                  say it's not a correct representation of a list at all. A linked list would
                  assign an id to each element, and have next refer to that id

                  <xsd:complexTyp e name="Llist" >
                  <xsd:simplecont ent>
                  <xsd:extensio n base="xsd:strin g">
                  <xsd:attribut e name="id" type="xsd:ID"/>
                  <xsd:attribut e name="next" type="xsd:IDREF " minOccurs='0'/>
                  </xsd:extension>
                  </xsd:complexType >

                  <xsd:element name='list1' type='Llist'/>

                  or something like that. The XML would come out like this:

                  <list1 id='a' next='b'>data 1</list1>
                  <list1 id='b' next='c'>data 2</list1>
                  <list1 id='c' next='d'>data 3</list1>
                  <list1 id='d'>data 4</list1>


                  Having said that, it doesn't make any sense. A linked list makes sense
                  as a data structure because it simplifies the implementation of certain
                  algorithms and sometimes makes memory management easier, but in an XML
                  document, it sounds goofy, and it's much more work since you have to
                  keep track of all the ids. Why not make it a real list?

                  <xsd:complexTyp e name="Rlist" >
                  <xsd:element name="item" type="xsd:strin g" minOccurs='0'
                  maxOccurs='unbo unded'/>
                  </xsd:complexType >

                  <xsd:element name='list2' type='Rlist'/>

                  which would appear like this

                  <list2>
                  <item>data 1</item>
                  <item>data 2</item>
                  <item>data 3</item>
                  <item>data 4</item>
                  </list2>
                  --

                  Patrick TJ McPhee
                  East York Canada
                  ptjm@interlog.c om

                  Comment

                  Working...