Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Extracting Base64 data from XML document

454278Aug 15 2007 — edited Nov 28 2007
Hi,

I am using a PL/SQL client to invoke a webservice which returns base64binary element. How can I convert this into Byte format?
The structure of the response is:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<FaxBarcodeResponse xmlns="http://tempuri.org/">
<FaxBarcodeResult>
<FaxID>int</FaxID>
<DocumentImage>
<Bytes>base64Binary</Bytes>
<ContentType>string</ContentType>
<DocumentName>string</DocumentName>
<ShowPDF>boolean</ShowPDF>
<Size>int</Size>
</DocumentImage>
</FaxBarcodeResult>
</FaxBarcodeResponse>
</soap:Body>
</soap:Envelope>

The pl/sql code that i am using is:

declare
soap_request varchar2(30000);
soap_respond varchar2(30000);
http_req utl_http.req;
http_resp utl_http.resp;
resp XMLType;
i integer;

begin
soap_request:= '<?xml version = "1.0" encoding = "UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthenticationHeader xmlns="http://tempuri.org/">
<Username>user1</Username>
<Password>xxxx</Password>
</AuthenticationHeader>
</soap:Header>
<soap:Body>
<FaxBarcode xmlns="http://tempuri.org/">
<VendorID>603</VendorID>
<DocumentTypeID>4131</DocumentTypeID>
<CabinetID>913</CabinetID>
<DocumentName>EXP1234</DocumentName>
</FaxBarcode>
</soap:Body>
</soap:Envelope>';

http_req:= utl_http.begin_request
( 'http://niws.mynewimageexpress.net/apolloservicev20.asmx'
, 'POST'
, 'HTTP/1.1'
);
utl_http.set_header(http_req, 'Content-Type', 'text/xml');
utl_http.set_header(http_req, 'Content-Length', length(soap_request));
utl_http.set_header(http_req, 'SOAPAction', 'http://tempuri.org/FaxBarcode');
utl_http.write_text(http_req, soap_request);
http_resp:= utl_http.get_response(http_req);
utl_http.read_text(http_resp, soap_respond);
utl_http.end_response(http_resp);
dbms_output.put_line(soap_respond);
resp:= XMLType.createXML(soap_respond);

resp:= resp.extract('/soap:Envelop/soap:Body/child::node()'
, 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"'
);

i:=0;
loop
dbms_output.put_line(substr(soap_respond,1+ i*255,250));
i:= i+1;
if i*250 > length(soap_respond) then
exit;
end if;
end loop;
end;

How can i extract the contents of <Bytes> </Bytes> in Byte format? I need to write it to a file (which is a barcode image).

Any pointers would be greatly appreciated.

Thanks
Ashish
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 26 2007
Added on Aug 15 2007
11 comments
2,803 views