I'm learning how to use XMLQuery and XMLtable features in Oracle 11g and I'm trying to use a variable instead of a specific string in XPath, when using a XMLTable query. For example:
DECLARE
px_return XMLTYPE
:= XMLTYPE (
'<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Header xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
</SOAP:Header>
<SOAP:Body xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<n0:validatePolicyCancelResponse xmlns:n0="urn:enterprise.com/ws/SAP/Finantial/MaintainMandate/V1">
<return>
<messageType>E</messageType>
</return>
</n0:validatePolicyCancelResponse>
</SOAP:Body>
</soap:Envelope>');
lv_msgType VARCHAR2 (20);
lv_urlString VARCHAR2 (40);
BEGIN
SELECT Return.msgType
INTO lv_msgType
FROM XMLTABLE (
xmlnamespaces (
DEFAULT 'enterprise.com/ws/SAP/Finantial/MaintainMandate/V1',
'http://schemas.xmlsoap.org/soap/envelope/' AS "soap",
'http://schemas.xmlsoap.org/soap/envelope/' AS "SOAP",
'enterprise.com/ws/SAP/Finantial/MaintainMandate/V1' AS "n0"),
'//soap:Envelope/SOAP:Body/n0:validatePolicyCancelResponse/return'
PASSING px_return
COLUMNS msgType VARCHAR2 (1) PATH 'messageType') Return;
DBMS_OUTPUT.put_line ('Message type: ' || lv_msgType);
END;
I use this query to parse the XML. But in some cases, the XML is different and I have a new XPath. I tried to put the XPath in a variable like this:
lv_urlString :=
'//soap:Envelope/SOAP:Body/n0:validatePolicyCancelResponse/return';
and substitute in the XMLTable query as this:
SELECT Return.msgType
INTO lv_msgType
FROM XMLTABLE (
xmlnamespaces (
DEFAULT 'enterprise.com/ws/SAP/Finantial/MaintainMandate/V1',
'http://schemas.xmlsoap.org/soap/envelope/' AS "soap",
'http://schemas.xmlsoap.org/soap/envelope/' AS "SOAP",
'enterprise.com/ws/SAP/Finantial/MaintainMandate/V1' AS "n0"),
lv_urlString
PASSING px_return
COLUMNS msgType VARCHAR2 (1) PATH 'messageType') Return;
I get the error:
ORA-19112: error raised during evaluation:
XVM-01081: [XPST0081] Invalid prefix
Can anyone help me to do this by reusing the same query, but applying different paths?