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 ;
Try
{
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;
}
Finally
{
FS. Flush ();
FS. Close ();
Isprintsuccess= True;
}
}
Else
{
// Xmlnode errormsgnode = replydoc. selectsinglenode ();
// Result = errormsgnode. innertext;
Result = Replydoc. outerxml;
}
Return result;
}