Schema representation of a "bitmask" type?

Discussion in 'XML' started by Andrey Brozhko, Dec 9, 2004.

  1. Hi

    I need to represent custom type system (ints, bytes, chars, enums,
    bitmasks, arrays and some other types) in xml. It is easy to see how to
    represent enums in xml (using xs:enumeration), the same is true for
    numeric types. Even arrays have an obvious description in schema:

    <complexType name="IntArray">
    <sequence>
    <element name="item" type="int" minOccurs="0" maxOccurs="unbounded"/>
    </sequence>
    </complexType>

    But how about bitmasks? What's the most beautiful way to represent a
    bitmask where values have names? It's just like enumeration but the
    value at any time can be a disjunction of any number of valid names.
    For example: if we have x = 0x01, y = 0x02 etc then the value may be
    either x, or x|y, or y etc.. but it can not be specified with 0x01. I
    don't think having "<myAttribute>x|y</myAttribute>" in the xml document
    is a good idea. Any suggestions?

    Cheers,
    Kapitan
     
    Andrey Brozhko, Dec 9, 2004
    #1
    1. Advertising

  2. OK, here is what I come up with:

    <xs:simpleType name="MyBitmapType">
    <xs:choice>
    <xs:element name="item" minOccurs="1" maxOccurs="unbounded">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:enumeration value="firstValue"/>
    <xs:enumeration value="secondValue"/>
    <xs:enumeration value="thirdValue"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:element>
    </xs:choice>
    </xs:simpleType>


    In this case something like:

    <?xml version="1.0" encoding="UTF-8"?>
    <test>
    <item>firstValue</item>
    <item>secondValue</item>
    </test>

    can be validated (which can be understood as "firstValue | secondValue").


    Unfortunately, it validates the following thing as well:

    <?xml version="1.0" encoding="UTF-8"?>
    <test>
    <item>firstValue</item>
    <item>firstValue</item>
    </test>

    which is not exactly wrong (as you can do "firstValue | firstValue" and
    the result will be OK), but it is not pretty... any suggestions?



    Andrey Brozhko wrote:
    > Hi
    >
    > I need to represent custom type system (ints, bytes, chars, enums,
    > bitmasks, arrays and some other types) in xml. It is easy to see how to
    > represent enums in xml (using xs:enumeration), the same is true for
    > numeric types. Even arrays have an obvious description in schema:
    >
    > <complexType name="IntArray">
    > <sequence>
    > <element name="item" type="int" minOccurs="0" maxOccurs="unbounded"/>
    > </sequence>
    > </complexType>
    >
    > But how about bitmasks? What's the most beautiful way to represent a
    > bitmask where values have names? It's just like enumeration but the
    > value at any time can be a disjunction of any number of valid names.
    > For example: if we have x = 0x01, y = 0x02 etc then the value may be
    > either x, or x|y, or y etc.. but it can not be specified with 0x01. I
    > don't think having "<myAttribute>x|y</myAttribute>" in the xml document
    > is a good idea. Any suggestions?
    >
    > Cheers,
    > Kapitan
    >
     
    Andrey Brozhko, Dec 10, 2004
    #2
    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. Rod Nibbe

    Bitmask & Graphics Question

    Rod Nibbe, Oct 26, 2004, in forum: Java
    Replies:
    2
    Views:
    1,640
    Rod Nibbe
    Oct 26, 2004
  2. Markus
    Replies:
    1
    Views:
    1,611
    Markus
    Nov 23, 2005
  3. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,295
    Stanimir Stamenkov
    Apr 25, 2005
  4. =?iso-8859-9?Q?Tongu=E7?= Yumruk

    Bitmask representation of integers

    =?iso-8859-9?Q?Tongu=E7?= Yumruk, Oct 8, 2003, in forum: Python
    Replies:
    3
    Views:
    886
    Scott David Daniels
    Oct 8, 2003
  5. Xah Lee
    Replies:
    0
    Views:
    349
    Xah Lee
    Apr 23, 2007
Loading...

Share This Page