Extract data from XMLTYPE variable - oracle

I have an XML below from which I am trying to extract the error tag data:
<ns1:updateStatusResponse xmlns:ns1="http://www.example.com/webservices">
<return href="#ID1"/>
</ns1:updateStatusResponse>
<ns3:OrderStatusUpdateResponse xmlns:ns3="http://www.example.com/com.example.com.ful.mod" id="ID1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns3:OrderStatusUpdateResponse">
<status xsi:type="xsd:string">ERROR</status>
<statusDetail xsi:type="xsd:string">Error occured when updating status for example</statusDetail>
</ns3:OrderStatusUpdateResponse>
I am using a logic like this, where resp is XMLTYPE and v_resp is VARCHAR2
v_resp := resp.EXTRACT (
'ns3:OrderStatusUpdateResponse/status/text()',
'xmlns:ns3="http://http://www.example.com/com.example.com.ful.mod" id="ID1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns3:OrderStatusUpdateResponse').getstringval ();
Whenever I run this in my code, I get an exception but no message.
Can someone please help me resolve this?

Related

Read value from XML within another XML: Mule

I am making a SOAP webservice call and I get the below response. I want to read the value in internal XML, the value is 12345684 in 1234684 in the below XML.
I was able to get internal XML using #[xpath3('//:processaResponse /return[2]')], store it in a flow variable and #[xpath3('/AckReg/DataArea/PRegistration/PRDet/Person/IDSet/:ID[#schemeName="aid"]/text()')].
This works when I try an online parser, but it doesn't read the value in Mule.
Is there any way to extract 1234684 in oa:ID tag using one XPath.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<ns3:TXID xmlns:ns3="http://a.d.r.test.com/"></ns3:TXID>
<ns3:SESSIONID xmlns:ns3="http://a.d.r.test.com/"></ns3:SESSIONID>
</soapenv:Header>
<soapenv:Body>
<ns3:processaResponse xmlns:ns3="http://a.d.r.test.com/" xmlns:ns2="http://p.r.test.com/">
<return>Hi</return>
<return>
<?xml version="1.0" encoding="UTF-8"?>
<AckReg
xmlns="http://www.test.com/e/1" languageCode="en-US" releaseID="normalizedString" systemEnvironmentCode="test" versionID="normalizedString"
xmlns:oa="www.test.com/r/9"
xsi:schemaLocation="http://www.test.com/a/1 ../test/test.xsd">
<Apa>
<oa:CreationDateTime>2018-04-05</oa:CreationDateTime>
</Apa>
<DataArea>
<Ack>
<OArea>
<o:Sender>
<o:LID schemeAgencyName="testi" schemeName="Application ID">test</o:LID>
</o:Sender>
</OArea>
<OriginalActionVerb/>
</Ack>
<PRegistration>
<testids>
<IDSet schemeAgencyName="try">
<oa:ID schemeName="abcid">1234684</oa:ID>
</IDSet>
</testids>
<PRDet>
<Person>
<IDSet schemeAgencyName="try">
<oa:ID schemeName="aid">1364561</oa:ID>
</IDSet>
<IDSet schemeAgencyName="enada">
<oa:ID schemeName="Employee ID">adsad</oa:ID>
</IDSet>
</Person>
<User>
<oa:ID/>
</User>
</PRDet>
</PRegistration>
</DataArea>
</AckReg>
</return>
</ns3:processaResponse>
</soapenv:Body>
</soapenv:Envelope>
In your expressions you were missing namespace prefixes or namespace wildcards *: on some nodes - so your expressions failed.
Is there any way to extract 1234684 in oa:ID tag using one XPath.
Combining both of your partial expressions is possible with namespace wildcards:
//*:processaResponse/return[2]/*:AckReg/*:DataArea/*:PRegistration/*:testids/*:IDSet/*:ID[#schemeName='abcid']/text()
Or you can use an absolute path with namespace wildcards:
/*:Envelope/*:Body/*:processaResponse/return[2]/*:AckReg/*:DataArea/*:PRegistration/*:testids/*:IDSet/*:ID[#schemeName='abcid']/text()
Output in both cases:
1234684
You can even use XmlSlurper class using groovy script to fetch that respective value.
root = new XmlSlurper( false, true).parseText(payload).declareNamespace('soapenv':"http://schemas.xmlsoap.org/soap/envelope/")

dbms_xmldom - How to get the <?xml tag

I am trying to get the line <?xml ....?> at the start of the XML document using the PL/SQL Package dbms_xmldom. Here is the code so far
declare
l_dom dbms_xmldom.DOMDocument;
l_clob clob;
l_node dbms_xmldom.DOMNode;
begin
l_dom := dbms_xmldom.newDomDocument;
l_node := dbms_xmldom.makeNode(l_dom);
l_node := dbms_xmldom.appendChild(l_node,
dbms_xmldom.makeNode(
dbms_xmldom.createElement(l_dom, 'root')
)
);
dbms_lob.createtemporary(l_clob, true);
dbms_xmldom.writeToClob(l_dom, l_clob);
dbms_output.put_line(l_clob);
end;
The output is:
<root/>
Expect:
<?xml version="1.0" encoding="UTF-8"?>
<root/>
Any pointers on how to do this would get great.
Just for the record - here is what you need to add
dbms_xmldom.setVersion(l_dom, '1.0" encoding="UTF-8');
after creating the document
The prolog is usually added automatically by XML serialization, so you shouldn't need to add it yourself, but if you want to you can with XMLRoot.
Your method for generating XML is quite inefficient. You should be looking at XMLElement, XMLForest, XMLAgg etc.
Here's a simple root and child example, with prolog in one line of code.
select XMLRoot(XMLElement("root", XMLElement("child", 12)), version '1.0') from dual
<?xml version="1.0"?>
<root>
<child>12</child>
</root>

Oracle error when parsing XML data: LPX-00663

Im getting below error, can anyone please help me resolve it.
the ORA-31011: the XML parsing failed The  the ORA-19202: the Error
Occurred in the XML processing support  The LPX-00663:. VM
String-Stack overflow
I could see solution as Increase the size bed of the VM StringStack in XmlXslVMCreate ()  in some websites but no steps given on how to do it.
From Oracle Documentation.
PL/SQL package DBMS_XSLPROCESSOR provides a convenient and efficient
way of applying a single style sheet to multiple documents. The
performance of this package is better than that of method transform(),
because the style sheet is parsed only once.
I had the same problem. Workaround was. Something like this.
DECLARE
v_out_clob CLOB;
v_in_xml XMLTYPE;
v_in_xsl XMLTYPE;
ctx_xslproc dbms_xslprocessor.processor;
v_in_xsl_dd dbms_xmldom.DOMDocument;
v_in_xml_dd dbms_xmldom.DOMDocument;
v_styleshet dbms_xslprocessor.stylesheet;
BEGIN
v_in_xml := new xmltype('<?xml version="1.0" encoding="ISO-8859-1"?><document></document>');
v_in_xsl := new xmltype('<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/">
<html>
<head>
<script type="text/javascript" src="jquery-1.11.1.min.js"></script>
</head>
<body>
<br />
</body>
</html>
</xsl:template>
</xsl:stylesheet>');
ctx_xslproc := dbms_xslprocessor.newProcessor;
v_in_xsl_dd := dbms_xmldom.newDOMDocument(v_in_xsl);
v_in_xml_dd := dbms_xmldom.newDOMDocument(v_in_xml);
v_styleshet := dbms_xslprocessor.newStyleSheet(v_in_xsl_dd, NULL);
dbms_lob.createtemporary(v_out_clob,FALSE);
dbms_xslprocessor.processXSL(ctx_xslproc,v_styleshet,v_in_xml_dd,v_out_clob);
dbms_xmldom.freeDocument(v_in_xsl_dd);
dbms_xmldom.freeDocument(v_in_xml_dd);
dbms_xslprocessor.freeProcessor(ctx_xslproc);
dbms_output.put_line(v_out_clob);
END;

WSO2 DSS call procedure with CLOB response raise ORA-22835 error

I have a Oracle procedure
TEST_XML_PARM_CALLER
call procedure
TEST_XML_PARM_CALLEE(parm1 IN CLOB, parm2 OUT CLOB)
via WSO2 ESB, WSO2 DSS.
The parm1 is CLOB parameter, send XML content from procedure TEST_XML_PARM_CALLER,
and the parm2 is CLOB parameter that return XML content from procedure TEST_XML_PARM_CALLEE.
The call from TEST_XML_PARM_CALLER to ESB to DSS to TEST_XML_PARAM_CALLEE is correct by CLOB content (string length great than 4000),
but return parameter(parm2) will raise error when length great than 4000, like bellow
ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 6024, maximum: 4000)
In WSO2 DSS, the configuration as below
<data name="test_xml_parm">
<config id="test_db">
<property name="carbon_datasource_name">test_db</property>
</config>
<query id="qry_test_xml_parm" useConfig="test_db">
<sql>call TEST_XML_PARM_CALLEE(?,?)</sql>
<result element="rcd" rowName="row">
<element column="rtn_clob" name="rtn_clob" xsdType="string"/>
</result>
<param name="clob_xml" ordinal="1" sqlType="STRING"/>
<param name="rtn_clob" ordinal="2" sqlType="STRING" type="OUT"/>
</query>
<operation name="op_test_xml_parm">
<call-query href="qry_test_xml_parm">
<with-param name="clob_xml" query-param="clob_xml"/>
</call-query>
</operation>
</data>
anyone can tell me how to fix it ?
This is an old question and I don't know about the wso2Dss version.
I had a similar problem with wso2DSS 4.4.2
1)set parameters sqlType to "CLOB"
2) replace ojdbc5.jar with ojdbc6.jar (or you will get java.lang.AbstractMethodError: setClob is abstract error.
I still have problems with xml (I must put input in CDATA and the response is ecaped (< => < ) but I should be able to deal with it on the ESB side.

Cannot use XPATH to get a value from SOAP response

Please help me to get value (013b92124ce54924) in "<web:prop value='013b92124ce54924' name='serviceId'></web:prop>"
I tried to use the xpath command unsuccessful:
/*/SOAP-ENV:Body/'ns':requestResponse/web:webapiResponse/web:data/web:prop[#name='serviceId']/#value
My SOAP response is as below:
`
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns:requestResponse xmlns:ns='http://www.phahahotel.com/BPS/sWebAPI'>
<web:webapiResponse xmlns:web='http://www.phahahotel.com/BPS/WebService' action='CreateServiceTel' transId='10100000009' clientId='svrcore'>
<web:respCode>0000</web:respCode>
<web:respDescription>Success</web:respDescription>
<web:data>
<web:prop value='SERTYPE' name='serviceType'></web:prop>
<web:prop value='013b92124ce54924' name='serviceId'></web:prop>
</web:data>
</web:webapiResponse>
</ns:requestResponse>
</SOAP-ENV:Body>
`
Thanks,
Remove the quotes around ns :-
% xpath test.xml "/*/SOAP-ENV:Body/ns:requestResponse/web:webapiResponse/web:data/web:prop[#name='serviceId']/#value"
Found 1 nodes:
-- NODE --
value="013b92124ce54924"

Resources