Reputation: 1992
i read some data from a device. Then i send this data to a web server via xml. The data should be represented in xml so this makes me convert characters between 0-31 because these chars can not be displayed on xml.
The question is how can i convert the chars between 0-31 decimal in a string like [00]abcde[01]fgh[02]...
Are there any built-in function in .net framework or any accepted pattern?
Thanks
Upvotes: 2
Views: 392
Reputation: 21752
You can simply encode the number as an XML entity you write &#
followed by the number and a semicolon
so 1 becomes 
and 13 becomes
and so on and so forth
However as noted by dan04 you can't represent 0 as a numeric character reference, so in the case where your data might include 0 you will have to use a different encoding. You could encode the entire binary data as base64
Most XML toolboxes will do the encoding to NCRs for you though so you really shouldn't have to worry about that
Upvotes: 2
Reputation: 888293
You should use standard XML encoding:

Your XML API will do that for you, so you don't need to worry about anything.
Upvotes: 6