Defining different elements in XML Schema

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fulvio.risso@gmail.com

    Defining different elements in XML Schema

    Hello guys.

    I would like to use the following two types of elements in my XML file:

    <field type="fixed" size="10"/>
    <field type="variable" expr="a+b"/>

    The problem is that I cannot find a way to define the proper XML
    schema. The problem is that I would like to define an element
    ("<field>") which may have different syntax according to the value of
    one of its attribute. It seems to me that a solution is to use
    "xsi:type=. .." in the XML file, but I don't want to do that.

    Does anybody have a solution for this (maybe stupid) problem?

    Cheers,

    fulvio

  • Soren Kuula

    #2
    Re: Defining different elements in XML Schema

    fulvio.risso@gm ail.com wrote:
    [color=blue]
    > Does anybody have a solution for this (maybe stupid) problem?[/color]

    Hi,

    The stupid one is not you..

    You can't specify the dependence of anything on attribute values in XML
    Schema.

    Relax NG can do it, and it's a much nicer language to work with (my
    opinion anyway).

    Soren

    Comment

    • Stan Kitsis [MSFT]

      #3
      Re: Defining different elements in XML Schema

      Can you use this instead?

      <fields>
      <fixed size="10"/>
      <variable expr="a+b"/>
      </fields>

      --
      Stan Kitsis
      Program Manager, XML Technologies
      Microsoft Corporation

      This posting is provided "AS IS" with no warranties, and confers no rights.

      <fulvio.risso@g mail.com> wrote in message
      news:1128602594 .461823.80710@g 43g2000cwa.goog legroups.com...[color=blue]
      > Hello guys.
      >
      > I would like to use the following two types of elements in my XML file:
      >
      > <field type="fixed" size="10"/>
      > <field type="variable" expr="a+b"/>
      >
      > The problem is that I cannot find a way to define the proper XML
      > schema. The problem is that I would like to define an element
      > ("<field>") which may have different syntax according to the value of
      > one of its attribute. It seems to me that a solution is to use
      > "xsi:type=. .." in the XML file, but I don't want to do that.
      >
      > Does anybody have a solution for this (maybe stupid) problem?
      >
      > Cheers,
      >
      > fulvio
      >[/color]


      Comment

      • Priscilla Walmsley

        #4
        Re: Defining different elements in XML Schema

        Hi,

        Just out of curiosity, why don't you want to use xsi:type? It's a
        simple matter of adding a namespace declaration in your document, and
        prefix to your type attributes:

        <field xsi:type="fixed " size="10"/>
        <field xsi:type="varia ble" expr="a+b"/>

        Priscilla

        ----------------------------------
        Priscilla Walmsley
        Author, Definitive XML Schema

        ----------------------------------

        *** Sent via Developersdex http://www.developersdex.com ***

        Comment

        Working...