3

I have to send binary data in XML and the standard way of doing that is using base64; however I have two options:

  • store the binary into a xs:base64binary
  • store the utf-8 encoded string representation of the base64 binary into a xs:string element

In the first case the schema reads:

 <xs:element name="Image" type="xs:base64Binary" />

In the second case the schema reads:

 <xs:element name="Image" type="xs:string" />

I suspect the first option is the more "correct", however it generates an XML that is bigger than the second option. The first element int the XML instance starts with "U1Vrc..." etc, the second one starts with "SUkqAAA.." etc.

Which one would be the most usual to see out there?

1
  • My experience is that most people don't use XML to send binary. But if you have to, use the base64Binary or hexBinary datatypes. Commented Mar 16, 2016 at 17:31

1 Answer 1

3

The best option is to not store binary data in the XML at all, send it separately and have the XML refer to the external data as needed. But if you have to store it in the XML directly, then base64Binary and hexBinary are the only built-in data types for binary data, but they are certainly not the only choice. There are other algorithms available that also encode data using alpha/numeric alphabets that are compatible with XML strings. Search around, or devise your own syntax that only encodes binary bytes that are restricted by XML and leave the rest unencoded.

Sign up to request clarification or add additional context in comments.

2 Comments

I understand the options, but I am trying to find out if there is an "accepted" or more widely used option since this will be given to 3rd parties to submit binary data to us.
Then you are basically stuck with base64, since that is the most compact and standard format that XML natively supports.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.