HexBinary byte order

Viewed 241

The first google link about HexBinary for XML shows link to this article.

There are an example of HexBinary representation:

"<?xml version="1.0" encoding="UTF-8"?>"
"3f3c6d78206c657673726f693d6e3122302e20226e656f636964676e223d54552d4622383e3f"

But when I try to implement encoding myself or use online converter, I receive next string:

"3C3F786D6C2076657273696F6E3D22312E302220656E636F64696E673D225554462D38223F3E"

Difference in byte order 3f3c vs 3c3f. It cannot be UTF-16 problem because it will produce something like 3c003f00 or 003c003f.

So, my question: is it problem in article (book from O'Reilly) or there are special rules for xsd:hexBinary which require to invert byte order?

1 Answers

There are no rules that tell you to invert the byte order.

The XSD specification for hexBinary data type is just:

hexBinary represents arbitrary hex-encoded binary data.

Note the word arbitrary - it doesn't tell you how to encode the data, or that you need to swap every two bytes after the encoding is done.

This is an error in the book. It seems likely the author of the book just copied and pasted text into a hex editor or converter, and didn't notice that with default settings it displays data in units of 2 bytes in little-endian byte order. This is an easy mistake to make if you're not used to working with binary data.

It doesn't look like this errata has been reported. If you want to, you can submit an errata to https://www.oreilly.com/catalog/errata.csp?isbn=9780596004217

Related