Options

How to extract a Base64 bitmap from XML in Navision?

pdjpdj Member Posts: 643
I get XML files with embedded Base64 encoded bitmaps. How do I get them decoded to a file so I can view the pictures?
I have tried using other automations, like adoStream and IXMLDOMText, but I'm getting nowhere. :-(

PS: I'm using 3.70 so please don't tell me to use XMLPorts :-)
Regards
Peter

Comments

  • Options
    Hi

    I have done that on version 3.70 using Automation objects.

    Write a function with 2 parameters:

    * P_FilePathToDecodeTo (Text[1024]): the path of the file that will be created with the decoded base64 information)

    * P_XMLDOMBase64 (Automation "'Microsoft XML, v3.0'.DOMDocument"): the XML DOM object that contains de base64 data

    The functiion just gets the base64 data from a node called <binary_data> from P_XMLDOMBase64. Then it loads that data in an ADOStrem object who performs the decode process.

    Like this:

    F_DecodeBase64DOM(P_FilePathToDecodeTo : Text[1024];VAR P_XMLDOMBase64 : Automation "'Microsoft XML, v3.0'.DOMDocument")

    L_XMLDOMNode := P_XMLDOMBase64.selectSingleNode('/binary_data');

    CREATE(L_ADOStream);
    L_ADOStream.Type := 1; // Binary mode
    L_ADOStream.Open;
    L_ADOStream.Write := L_XMLDOMNode.nodeTypedValue;
    L_ADOStream.SaveToFile(P_FilePathToDecodeTo);
    L_ADOStream.Close;
    CLEAR(L_ADOStream);



    The L_ADOStream variable is just an Automation 'Microsoft ActiveX Data Objects 2.7 Library'.Stream.

    This method is the fastest I have found to decode base64 data. There are base64 COM objectes on the net, but none is as fast the method suggested.


    Toni
  • Options
    pdjpdj Member Posts: 643
    Thanks a lot for your reply, however; I can't get it to work :-(

    I get an error in this line:
    L_ADOStream.Write := L_XMLDOMNode.nodeTypedValue;

    Like this:
    The call to member Write failed. ADODB.Stream returned the following message:
    The arguments are of an incorrect type or is outside the the specified area, or a conflict has occourded. (my own translation)

    My code is like this:
    Variables:
    adoStream   Automation	'Microsoft ActiveX Data Objects 2.7 Library'.Stream	
    xmlDom      Automation	'Microsoft XML, v3.0'.DOMDocument	
    xmlNode     Automation	'Microsoft XML, v3.0'.IXMLDOMNode	
    
    OnRun()
    CREATE(xmlDom);
    IF NOT xmlDom.load(<my file) THEN
      ERROR('file not found');
    
    xmlNode := xmlDom.selectSingleNode(<my node>);
    IF ISCLEAR(xmlNode) THEN
      ERROR('Node not found');
    
    CREATE(adoStream);
    adoStream.Type := 1; // Binary mode
    adoStream.Open;
    adoStream.Write := xmlNode.nodeTypedValue;
    adoStream.SaveToFile(<new file>);
    adoStream.Close;
    CLEAR(adoStream);
    
    Any idea on what to do?
    Regards
    Peter
  • Options
    Hi

    Oh yes, the base64 XML node must have a particular dataType. That way the ADO objects know what they are getting and know the job to be done.

    The XML node that contains the base64 data should have as dataType the value 'bin.base64', and it should look like this:
    <mynode xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="bin.base64">BASE64 DATA</mynode>
    

    The easiest way to set the datatype for an XML node is perhaps something like
    XMLDOMNode.dataType := 'bin.base64'
    

    in the node creation.


    Toni
  • Options
    pdjpdj Member Posts: 643
    Perfect, I just inserted the line before the adoStream.Write and that was it.

    Thanks.
    Regards
    Peter
Sign In or Register to comment.