Parsing Web Service Response in Oracle 9i
Posted
by zechariahs
on Stack Overflow
See other posts from Stack Overflow
or by zechariahs
Published on 2010-04-07T22:49:36Z
Indexed on
2010/04/07
22:53 UTC
Read the original article
Hit count: 392
I'm having trouble parsing an XML response from a web service. I have a feeling this is due to a namespace issue. But, after 4 hours of research, trial-and-error, and head-banging I haven't been able to resolve it. Please help.
My goal is to get a dbms_xmldom.DOMNodeList that contains "ERRORS" nodes.
XML Response:
<?xml version="1.0" encoding="ISO-8859-1"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetMailDataResponse xmlns="https://www.customnamespacehost.com/webservicename">
<GetMailDataResult>
<Errors xmlns="">
<ErrorDetail>Access Credentials Invalid</ErrorDetail>
</Errors>
</GetMailDataResult>
</GetMailDataResponse>
</soap:Body>
Code:
Unfortunately this code compiles but doesn't work. Error: "ORA-31013: Invalid XPATH expression." I believe this is due to the multiple namespaces defined in L_NS variable. I tried setting L_XPATH: "/soap:Envelope/soap:Body" and L_NS: "xmlns:soap="http://schemas.xmlsoap.org/soap/envelope"" but L_NL_RESULTS ends up being null.
-- Variable Declarations --
P_XML XMLTYPE;
L_CODE_NAME VARCHAR2(1000) := 'PKG_CIS_WS.FNC_STAGE_DATA';
L_XML_DOC dbms_xmldom.DOMDocument;
L_NL_RESULTS dbms_xmldom.DOMNodeList;
L_NL_DONOR_SCREENING_RESULTS dbms_xmldom.DOMNodeList;
L_N_RESULT dbms_xmldom.DOMNode;
L_XPATH VARCHAR2(4000);
L_NS VARCHAR2(4000);
L_TEMP VARCHAR2(4000);
-- Code Snippet --
L_XML_DOC := dbms_xmldom.newDOMDocument(P_XML);
L_XPATH := '/soap:Envelope/soap:Body/a:GetMailDataResponse/GetMailDataResult';
L_NS := 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope"' ||
'xmlns:a="https://www.customnamespacehost.com/webservicename"';
L_NL_RESULTS := dbms_xslprocessor.selectNodes(
dbms_xmldom.makeNode(L_XML_DOC)
, L_XPATH
, L_NS);
if not DBMS_XMLDOM.ISNULL(L_NL_RESULTS) then
FOR RESULTS_REC IN 0 .. dbms_xmldom.getLength(L_NL_RESULTS) - 1 LOOP
L_N_RESULT := dbms_xmldom.item(L_NL_RESULTS, RESULTS_REC);
L_TEMP := dbms_xmldom.GETNODENAME(L_N_RESULT);
prc_bjm(L_CODE_NAME, 'L_TEMP = ' || L_TEMP, SQLCODE);
dbms_xslprocessor.valueOf(L_N_RESULT, 'Errors/ErrorDetail/text()', L_TEMP);
prc_bjm(L_CODE_NAME, 'L_TEMP = ' || L_TEMP, SQLCODE);
END LOOP;
else
prc_bjm(L_CODE_NAME, 'No nodes for: ' || L_XPATH || '(' || L_NS || ')', SQLCODE);
end if; -- if not DBMS_XMLDOM.ISNULL(L_NL_RESULTS)
© Stack Overflow or respective owner