XSd problem,...

Discussion in 'XML' started by mavis, Jun 6, 2006.

  1. mavis

    mavis Guest

    If I want to assign different value to different versions as the
    followings:

    <versions>
    <version>
    <name> a20 </name>
    <value> 10 </value>
    </version>

    <version>
    <name> b40 </name>
    <value> 50 </value>
    </version>

    <version>
    <name> others</name>
    <value> 5 </value>
    </version>
    </versions>

    I guess it cannot be simplified as below, even if we can use <xs:choice
    maxOccurs="unbounded"> to define elements in any order with any
    occurrences.. the problem is we cannot identify corresponding value for
    each version...

    <versions>
    <version> a20 </version>
    <value> 10 </value>

    <version> b40 </version>
    <value> 50 <value>

    <version> others </version>
    <value> 5 </value>
    </versions>

    Am I right? Could anyone confirm me about this if possible?
    Thanks a lot!
    mavis, Jun 6, 2006
    #1
    1. Advertising

  2. mavis

    George Bina Guest

    Hi,

    You can define a sequence in the schema and specify the name and value
    inside that sequence, then set the occurances on the sequence to handle
    more versions, like below for instance:

    <xs:element name="versions">
    <xs:complexType>
    <xs:sequence maxOccurs="unbounded">
    <xs:element name="version"/>
    <xs:element name="value"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    Getting the value for a version element should be easy, in XSLT for
    instance if you match on a version element the the value is given by
    the following XPath expression (assuming the document is valid against
    the schema)

    following-sibling::*[1]

    Best Regards,
    George
    ---------------------------------------------------------------------
    George Cristian Bina
    <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    http://www.oxygenxml.com
    George Bina, Jun 6, 2006
    #2
    1. Advertising

  3. mavis

    mavis Guest

    Thanks a lot!!!
    Will I get problem if I need to access different values through XPath?
    /versions/version/ ? /versions/value?
    how can I get corresponding value for each version?
    Mavis

    George Bina wrote:
    > Hi,
    >
    > You can define a sequence in the schema and specify the name and value
    > inside that sequence, then set the occurances on the sequence to handle
    > more versions, like below for instance:
    >
    > <xs:element name="versions">
    > <xs:complexType>
    > <xs:sequence maxOccurs="unbounded">
    > <xs:element name="version"/>
    > <xs:element name="value"/>
    > </xs:sequence>
    > </xs:complexType>
    > </xs:element>
    >
    > Getting the value for a version element should be easy, in XSLT for
    > instance if you match on a version element the the value is given by
    > the following XPath expression (assuming the document is valid against
    > the schema)
    >
    > following-sibling::*[1]
    >
    > Best Regards,
    > George
    > ---------------------------------------------------------------------
    > George Cristian Bina
    > <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    > http://www.oxygenxml.com
    mavis, Jun 6, 2006
    #3
  4. mavis

    George Bina Guest

    Hi Mavis,

    If you reach a version element then the corresponding value is
    following-sibling::*[1].

    Best Regards,
    George
    ---------------------------------------------------------------------
    George Cristian Bina
    <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    http://www.oxygenxml.com

    mavis wrote:
    > Thanks a lot!!!
    > Will I get problem if I need to access different values through XPath?
    > /versions/version/ ? /versions/value?
    > how can I get corresponding value for each version?
    > Mavis
    >
    > George Bina wrote:
    > > Hi,
    > >
    > > You can define a sequence in the schema and specify the name and value
    > > inside that sequence, then set the occurances on the sequence to handle
    > > more versions, like below for instance:
    > >
    > > <xs:element name="versions">
    > > <xs:complexType>
    > > <xs:sequence maxOccurs="unbounded">
    > > <xs:element name="version"/>
    > > <xs:element name="value"/>
    > > </xs:sequence>
    > > </xs:complexType>
    > > </xs:element>
    > >
    > > Getting the value for a version element should be easy, in XSLT for
    > > instance if you match on a version element the the value is given by
    > > the following XPath expression (assuming the document is valid against
    > > the schema)
    > >
    > > following-sibling::*[1]
    > >
    > > Best Regards,
    > > George
    > > ---------------------------------------------------------------------
    > > George Cristian Bina
    > > <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    > > http://www.oxygenxml.com
    George Bina, Jun 9, 2006
    #4
  5. mavis

    mavis Guest

    Thanks a lot. George.

    George Bina wrote:
    > Hi Mavis,
    >
    > If you reach a version element then the corresponding value is
    > following-sibling::*[1].
    >
    > Best Regards,
    > George
    > ---------------------------------------------------------------------
    > George Cristian Bina
    > <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    > http://www.oxygenxml.com
    >
    > mavis wrote:
    > > Thanks a lot!!!
    > > Will I get problem if I need to access different values through XPath?
    > > /versions/version/ ? /versions/value?
    > > how can I get corresponding value for each version?
    > > Mavis
    > >
    > > George Bina wrote:
    > > > Hi,
    > > >
    > > > You can define a sequence in the schema and specify the name and value
    > > > inside that sequence, then set the occurances on the sequence to handle
    > > > more versions, like below for instance:
    > > >
    > > > <xs:element name="versions">
    > > > <xs:complexType>
    > > > <xs:sequence maxOccurs="unbounded">
    > > > <xs:element name="version"/>
    > > > <xs:element name="value"/>
    > > > </xs:sequence>
    > > > </xs:complexType>
    > > > </xs:element>
    > > >
    > > > Getting the value for a version element should be easy, in XSLT for
    > > > instance if you match on a version element the the value is given by
    > > > the following XPath expression (assuming the document is valid against
    > > > the schema)
    > > >
    > > > following-sibling::*[1]
    > > >
    > > > Best Regards,
    > > > George
    > > > ---------------------------------------------------------------------
    > > > George Cristian Bina
    > > > <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    > > > http://www.oxygenxml.com
    mavis, Jun 9, 2006
    #5
    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,097
    Markus
    Nov 22, 2005
  2. Rick Razzano

    XSD document for XSD defintion

    Rick Razzano, Sep 26, 2003, in forum: XML
    Replies:
    1
    Views:
    484
    C. M. Sperberg-McQueen
    Sep 26, 2003
  3. Replies:
    1
    Views:
    854
    Martin Honnen
    Jan 14, 2004
  4. Peter Aberline

    xsd:any as a child of xsd:all

    Peter Aberline, Apr 5, 2004, in forum: XML
    Replies:
    0
    Views:
    784
    Peter Aberline
    Apr 5, 2004
  5. Bernd Oninger
    Replies:
    1
    Views:
    525
    Henry S. Thompson
    Jun 30, 2004
Loading...

Share This Page