Base64-solution for storing images in XML

Source: Internet
Author: User
Recently, I am working on interfaces with FedEx/ups. The XML returned by them contains the label information. How can I convert the seemingly garbled information into images?

In fact, in their XML, the image is fromBinary filesConvertBase64 encodingStored in files. The benefit of doing so is to reduce the XML volume.
Read from XMLBase64After encoding, it needs to be decodedBinaryAnd then write the image.

If you use C # to process this process, you can use the class that comes with. Net to process it.

Decoding: Data = system. Convert. frombase64string (labelcontent );

My original method is as follows: Public   Virtual   String Printlable ( String Replyxml)
String Result =   "" ;

Xmldocument replydoc =   New Xmldocument ();
Replydoc. loadxml (replyxml );
// Xmlnode errornode = replydoc. selectsinglenode (errorpath );
If ( This . Issendsucessfully (replydoc ))
// No error
Xmlnode labelnode = Replydoc. selectsinglenode (labelcontentpath );

String Labelcontent = Labelnode. innertext;

Replydoc =   Null ;
Labelnode =   Null ;

Byte [] Data =   New   Byte [Labelcontent. Length];

Data = System. Convert. frombase64string (labelcontent );

String Filename = Box. work_order_id.tostring () + Box. box_id.tostring () + Exename;

Filestream FS =   Null ;
FS = File. openwrite (labelfolder + Filename );
FS. Write (data, 0 , Data. Length );
Result =   " Please check labels in "   + Labelfolder +   " , Labels are there! " ;

Catch (Exception E)
Result=E. message;
FS. Flush ();
FS. Close ();

Isprintsuccess= True;
// Xmlnode errormsgnode = replydoc. selectsinglenode ();
// Result = errormsgnode. innertext;
Result = Replydoc. outerxml;


Return result;


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.