Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Schema representation of a "bitmask" type?

Reply
Thread Tools

Schema representation of a "bitmask" type?

 
 
Andrey Brozhko
Guest
Posts: n/a
 
      12-09-2004
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

 
Reply With Quote
 
 
 
 
Andrey Brozhko
Guest
Posts: n/a
 
      12-10-2004
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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with schema-validation and property "http://apache.org/xml/properties/schema/external-schemaLocation" Markus Java 1 11-23-2005 02:41 PM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
Can JAXB be used to get a Java representation of an XML Schema? SOndei Java 0 01-15-2004 09:20 AM
Schema Metadata not a Metadata Schema Brett Selleck XML 1 09-04-2003 05:02 PM
Re: Convert DB2 schema to XML Schema Klaus Johannes Rusch XML 0 08-06-2003 11:23 AM



Advertisments