Insert images to XML file
The most common way of doing this is to include the binary as base-64 in an element. However, this is a workaround, and adds a bit of volume to the file.
For example, this is the bytes 00 to 09 (note we needed 16 bytes to encode 10 bytes worth of data):
<xml><image>AAECAwQFBgcICQ==</image></xml>
how you do this encoding varies per architecture. For example, with .NET you might use Convert.ToBase64String
, or XmlWriter.WriteBase64
.
Since XML is a text format and images are usually not (except some ancient and archaic formats) there is no really sensible way to do it. Looking at things like ODT or OOXML also shows you that they don't embed images directly into XML.
What you can do, however, is convert it to Base64 or similar and embed it into the XML.
XML's whitespace handling may further complicate things in such cases, though.