Skip to Main Content

DevOps, CI/CD and Automation

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!

Create XML using PLSQL Adding Namespace and Null Handling at the same time

user11292761Jul 6 2016 — edited Jul 7 2016

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

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 4 2016
Added on Jul 6 2016
1 comment
2,288 views