Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Real binary block in XML (C++)?

Is it possible to integrate a real (not encoded in characters) binary block (best with defined byte-order and word-length) into an XML file?

like image 544
ares_games Avatar asked Feb 11 '13 16:02

ares_games


People also ask

What is binary data in XML?

Binary XML is typically used in applications where the performance of standard XML is insufficient, but the ability to convert the document to and from a form (XML) which is easily viewed and edited is valued. Other advantages may include enabling random access and indexing of XML documents.

Can XML have binary data?

In many cases, XML files are both machine-generated and machine-consumed. In other words, many XML text files aren't used directly by humans. This is the rather paradoxical aspect of XML technology—it's text-based and non-binary, but is often used as though it's binary.

How do we store binary data in XML?

There are two methods of encoding binary data in an XML document. The base64Binary encoding makes better use of the available XML characters, and on average a base64-encoded binary field is 2/3 the size of its hexBinary equivalent. Base64Binary is widely used by the MIME format and by various XML-based standards.


1 Answers

No, it is not possible while keeping within the xml standard.

The allowable set of characters in a parsed XML entity is tab, carriage return, linefeed, and valid unicode characters. There are various bytes that fall outside of this allowable range, most prominently 0x0, but also 0x1 - 0x8, 0xB - 0xC, and 0xE - 0x1F (i.e., most values that are classically ASCII control characters).

You can't even include them as numeric entities, since they aren't valid characters. i.e., the following will not validate:

<test>
    Testing ^A: &#x1;
</test>

See http://www.w3.org/TR/2006/REC-xml11-20060816/#charsets

like image 191
evil otto Avatar answered Sep 28 '22 07:09

evil otto