2 Replies Latest reply: Dec 27, 2012 4:09 AM by 971919 RSS

    Image encoding in XML report definition

      For a number of reports I have the Report definition in XML-format. These files contain embedded images.

      How do I extract image-files from the xml's. It doesn't look like the strings for the images are not base16 or base64 encoded?
        • 1. Re: Image encoding in XML report definition
          Are you working with something like this?
          <?xml version="1.0" encoding="WINDOWS-1252" ?>
          <report name="MODULE1" DTDVersion="">
            <xmlSettings xmlTag="MODULE1" xmlPrologType="text">
            <![CDATA[<?xml version="1.0" encoding="&Encoding"?>]]>
              <systemParameter name="MODE" initialValue="Default"/>
              <systemParameter name="ORIENTATION" initialValue="Default"/>
            <section name="main">
                <image name="B_1">
                  <geometryInfo x="0.00000" y="0.00000" width="8.31250" height="6.25000"
                  <visualSettings fillPattern="transparent" fillBackgroundColor="black"
                   linePattern="transparent" lineBackgroundColor="black"/>
                    <point x="0.00000" y="0.00000"/>
                    <point x="8.31250" y="6.25000"/>
                    <point x="0.00000" y="0.00000"/>
                    <point x="8.31250" y="6.25000"/>
                  <binaryData encoding="hexidecimal" dataId="image.B_1">
          FF8DFF0E 0001A464 94640010 10100006 00060000 FFBD0048 0001B0C0 E0C0A001
          E0D0E021 11013181 82A18161 61811332 52D182A3 33D3C393 33837304 84C5E404
          44755473 8305D615 75F52676 8676E3D4 17970746 87C55676 36101121 21815181
          F2A1A1F2 36248324 36363636 36363636 36363636 36363636 36363636 36363636
          36363636 36363636 36363636 36363636 36363636 36363636 3636FF4C 102A0000
          D29681A8 4EB94557 F3D8D588 912F1FCE A2478278 4E157FE8 D3B2F257 A1906D14
          A809D102 9F646EFF 007CA66A B08C98EF 2E5344BB 4978EEAD 55093F75 6A4E8D29
          345ECCA0 4F537A2C 9CB424CB 8DDE0D7D 53D4D002 D3E32E6D 1942F70F 5D29740C
          7CF15A56 1A469E72 F449A09D 918DE7CF 5F9F877A 17106FEF 474C484E 6F41C067
          0D1338AF 1D06311A 4E6608F0 F4C40540 859FBFE7 579924E1 495C31FF 9D
            <![CDATA[<%@ taglib uri="/WEB-INF/lib/reports_tld.jar" prefix="rw" %> 
          <%@ page language="java" import="java.io.*" errorPage="/rwerror.jsp" session="false" %>
          <%@ page contentType="text/html;charset=ISO-8859-1" %>
          <rw:report id="report"> 
          <rw:objects id="objects">
          <meta name="GENERATOR" content="Oracle 9i Reports Developer"/>
          <title> Your Title </title>
          <rw:style id="yourStyle">
             <!-- Report Wizard inserts style link clause here -->
          <rw:dataArea id="yourDataArea">
             <!-- Report Wizard inserts the default jsp here -->
            <reportPrivate versionFlags2="0" templateName="rwbeige"/>
          Image data is encoded in hexadecimal format (base16) but the hex digits are reversed compared to the original byte sequence.
          For example, the first eight bytes in the source are :
          FFD8FFE0 00104A46
          but appears as
          FF8DFF0E 0001A464
          in the XML file.

          You'll need a small program to read the file, extract the hex binary stream, process it and write back the data to a file.

          Example in PL/SQL (tested on db version :
           fid     utl_file.file_type;
           len     PLS_INTEGER := 1024;
           buf     RAW(512);
           module_name VARCHAR2(260) := 'MODULE1';
           dir_name    VARCHAR2(30) := 'TEST_DIR';
            for r in (
              /* extract all image elements */
              select img_name
                   , regexp_replace(img_data, '\s+') as img_data
              from xmltable('//body/image'
                    passing xmltype(bfilename(dir_name, module_name||'.xml'), nls_charset_id('WE8MSWIN1252'))
                    columns img_name varchar2(30) path '@name'
                          , img_data clob         path 'binaryData'
              /* output file */
              fid := utl_file.fopen(dir_name, module_name || '_' || r.img_name || '.jpg', 'wb', 32767); 
              for i in 0..trunc((dbms_lob.getlength(r.img_data) - 1 )/len)
                /* read 1k of hex data and convert to binary */
                buf := hextoraw(
                           dbms_lob.substr(r.img_data, len, i*len + 1)
                         , '(.)(.)'
                         , '\2\1'
                utl_file.put_raw(fid, buf);
              end loop;
            end loop;
          • 2. Re: Image encoding in XML report definition

            This was what I was looking for!

            I now wonder why I didn't notice that it was this simple!

            Regards, Herman