Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Representing byte array as an XSD schema

Tags:

jaxb

xsd

What is the best way to represent a byte array as an XSD schema? I have a byte input which I need to parse and to feed to Java objects generated by JAXB out of an XSD schema for future validation. Every piece of information in my input is defined by offset and the length. I would like to attach this information to my elements so I could then read it from generated classes and use for parsing. The only way to attach such additional information to an Element I can think of is representing every Element as a Complex Type and then adding attributes to the complex Element and restrictions – to the simple Element wrapped by this complex Element. The problem with this approach (in addition to the Schema looking messy) is that JAXB will create separate class for every Element (Complex Type). And I will have a lot of fields in my input. :) The second issue is that I will in fact attach attributes and restrictions (which I need for validation) to different elements (wrapped simple element and the complex wrapper). So I will need to find a way to figure out that they in fact represent the same piece of information. I hope all this make sense. :) Basically my question is: can you think of a more elegant way to attach position and length information to an XSD element that represents the corresponding piece of a byte array? Thanks!

like image 630
Atman Avatar asked Feb 25 '23 07:02

Atman


1 Answers

What is the best way to represent a byte array as an XSD schema? I have a byte input which I need to parse and to feed to Java objects generated by JAXB out of an XSD schema for future validation.

JAXB will convert a byte[] to/from elements and attributes of type xsd:base64Binary.

For information on starting from XML schema see:

  • http://bdoughan.blogspot.com/2011/05/schema-to-java-xmlmimetype.html

For information on starting from Java classes see:

  • http://bdoughan.blogspot.com/2011/03/jaxb-web-services-and-binary-data.html
like image 172
bdoughan Avatar answered Mar 05 '23 03:03

bdoughan