?
Solved

Write Binary Data into XML with Linq

Posted on 2009-04-30
5
Medium Priority
?
1,100 Views
Last Modified: 2013-12-17
I read some values of the registry and write them to a XML with Linq. Some Values have binary characters and look like this:

ήì\ÎQÝÜ$Ñ.Ì6Å·xxµ0©ÐQfô:S9}:&X¨Pܾ×CPkÑ

The program crashes when I try to write those values into the XML. How can I write these values into the xml?
0
Comment
Question by:schubduese
  • 3
5 Comments
 
LVL 18

Expert Comment

by:lludden
ID: 24274446
You will want to MIME encode any binary data you store in an XML document.  See http://www.xml.com/pub/a/98/07/binary/binary.html

I use one of the components in IP!Works (www.nsoftware.com) to do MIME encodings.  If you want to uuencode it instead, there is code here http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=351

0
 
LVL 9

Accepted Solution

by:
Sreedhar Vengala earned 1500 total points
ID: 24274934
Simplest way is to base64 encode the data and then set it as element text. Convert.ToBase64String and Convert.FromBase64String should get you started.
0
 

Author Comment

by:schubduese
ID: 24277077
Could you give me a C# example?

Do I have to check every reg entry I read for bin values?
0
 

Author Comment

by:schubduese
ID: 24277468
I can write the Data Base64 Encoded with this:

        public static string Encode(string str)
        {
            byte[] encbuff = System.Text.Encoding.UTF8.GetBytes(str);
            return Convert.ToBase64String(encbuff);
        }

That means the routine wich Shows the XML in the Application needs this routine:

        public string Decode(string str)
        {
            byte[] decbuff = Convert.FromBase64String(str);
            return System.Text.Encoding.UTF8.GetString(decbuff);
        }

right?

That means writing the binary into the XML as it is, doesn't work?
0
 

Author Comment

by:schubduese
ID: 24277695
There we go with the next Error Message

The Key which failed, works now. But if I scan HKLM\Software\Windows\CurrentVersion it fails and says that the binary value (hex code 0xFFFF) is not a valid sign!

Any help on this?
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month15 days, 21 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question