Hi,
I'm new to PLSQL to write XML, I need to produce an XML result with namespace and null handling (xsi:nil="true"). I only know how to do it one of them in different way.
I'm using Oracle 12.
Namespace:
<EMP_INFO xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:oracle-com:schemas:emp_info_management_receive_emp_info_request">
Empty tag:
<EMP_DOB xsi:nil = "true"/>
I use DBMS_XMLGEN.setNullHandling to set all null field to xsi:nil="true". But I don't have with this mathoed how to set the namespace.
OPEN refcur FOR 'SELECT EMP_NO, EMP_NAME, EMP_DOB FROM EMP_TAB WHERE EMP_NO = :1' USING emp_no_;
ctx := DBMS_XMLGEN.newContext(refcur);
DBMS_XMLGEN.setRowSetTag(ctx, NULL);
DBMS_XMLGEN.setRowTag(ctx, 'EMP_INFO');
DBMS_XMLGEN.setNullHandling(ctx, 1);
DBMS_XMLGEN.getXML(ctx, xmldoc,DBMS_XMLGEN.NONE);
I use XMLAttributes to add namespace but this method, I'm not sure how to make those empty tag to <EMP_DOB xsi:nil = "true"/>, it will only produce result in <EMP_DOB></EMP_DOB>
SELECT XMLELEMENT("EMP_INFO", XMLAttributes('http://www.w3.org/2001/XMLSchema-instance' AS "xmlns:xsi", 'urn:oracle-com:schemas:emp_info_management_receive_emp_info_request' AS "xmlns"),
XMLELEMENT("EMP_NO",EMP_NO),
XMLELEMENT("EMP_NAME",EMP_NAME),
XMLELEMENT("EMP_DOB",TO_CHAR(EMP_DOB,'YYYY-MM-DD"T"HH24:MI:SS'))
) XML_DATA
FROM EMP_TAB
Please advice how to produce that 2 requirement using any one method?
Thanks
Chin