Hello DFDL community,
My input file is binary and in little endian order.
Some fields in the input file represent addresses/pointers. For example:
00 00 00 40
I've decided that the XML should show the hex digits, so I do this:
<xs:element name="Address_of_relocation_table"
type="xs:hexBinary"
dfdl:length="4"
dfdl:lengthKind="explicit"
dfdl:lengthUnits="bytes" />
However, that results in this XML output:
<Address_of_relocation_table>00000040</Address_of_relocation_table>
I'm sure the person who views that XML will not realize that the hex digits are
shown in little endian form. I really want the XML output to show the hex
digits as we humans ordinarily view numbers: from most significant digit to
least significant digit. So, I want the XML output to be this:
<Address_of_relocation_table>40000000</Address_of_relocation_table>
In other words, I want to reverse the input's bytes.
I figured out one way to accomplish this reversal. In a hidden group, have 4
elements, one for each byte:
<xs:group name="hidden_hexBinary4_Group">
<xs:sequence>
<xs:element name="Hidden_byte1" type="hexBinary1"
dfdl:outputValueCalc='{ . }' />
<xs:element name="Hidden_byte2" type="hexBinary1"
dfdl:outputValueCalc='{ . }' />
<xs:element name="Hidden_byte3" type="hexBinary1"
dfdl:outputValueCalc='{ . }' />
<xs:element name="Hidden_byte4" type="hexBinary1"
dfdl:outputValueCalc='{ . }' />
</xs:sequence>
</xs:group>
where hexBinary1 is this simpleType:
<xs:simpleType name="hexBinary1" dfdl:length="1" dfdl:lengthKind="explicit"
dfdl:lengthUnits="bytes">
<xs:restriction base="xs:hexBinary"/>
</xs:simpleType>
Then, when I declare the Address_of_relocation_table element, I reverse the 4
elements and concatenate their values:
<xs:sequence dfdl:hiddenGroupRef="hidden_hexBinary4_Group" />
<xs:element name="Address_of_relocation_table" type="xs:string"
dfdl:inputValueCalc='{
fn:concat( xs:string(../Hidden_byte4),
xs:string(../Hidden_byte3),
xs:string(../Hidden_byte2),
xs:string(../Hidden_byte1))}'/>
That works, but for the next address/pointer I have to create another hidden
group. Ugh! I've got dozens of these hidden groups containing four 1-byte
elements. There has to be a better way!
Is there a better way to reverse the input bytes?
/Roger