Question : Read XML through oracle view and ordered output

Hi,

I have a xmlfile which needs to be read by oracle and provide the data as view. I have provided the sample xml and view.

<?xml version="1.0" encoding="UTF-8"?>
<Employees>
      <Employee AccountNumber="123456">
            <AccountOpenDate>01-JAN-2000</AccountOpenDate>
            <EmpPayment>
                  <Commissions>
                        <CommissionByMonth>
                              <AsOfMonthEnd>200901</AsOfMonthEnd>
                              <Commission>123456</Commission>
                        </CommissionByMonth>
                        <CommissionByMonth>
                              <AsOfMonthEnd>200904</AsOfMonthEnd>
                              <Commission>789696</Commission>
                        </CommissionByMonth>
                        <CommissionByMonth>
                              <AsOfMonthEnd>200903</AsOfMonthEnd>
                              <Commission>345678</Commission>
                        </CommissionByMonth>
                        <CommissionByMonth>
                              <AsOfMonthEnd>200902</AsOfMonthEnd>
                              <Commission>23456</Commission>
                        </CommissionByMonth>
                  </Commissions>
            </EmpPayment>
      </Employee>
</Employees>


create view emp_cmmsn_dtl_vw as
select  
 EXTRACTVALUE(xseq.column_value, '/Employee/@AccountNumber')   AS AccountNumber,
 EXTRACTVALUE(xseq.column_value, '/Employee/AccountOpenDate')   AS  AccountOpenDate,
EXTRACTVALUE(xseq.column_value, '/Employee/EmpPayment/Commissions/CommissionByMonth[1]/AsOfMonthEnd')       AS CMMSNASOFM1
, EXTRACTVALUE(xseq.column_value, '/Employee/EmpPayment/Commissions/CommissionByMonth[2]/AsOfMonthEnd')       AS CMMSNASOFM2
,  EXTRACTVALUE(xseq.column_value, '/Employee/EmpPayment/Commissions/CommissionByMonth[3]/AsOfMonthEnd')       AS CMMSNASOFM3
,   EXTRACTVALUE(xseq.column_value, '/Employee/EmpPayment/Commissions/CommissionByMonth[4]/AsOfMonthEnd')       AS CMMSNASOFM4
,   EXTRACTVALUE(xseq.column_value, '/Employee/EmpPayment/Commissions/CommissionByMonth[1]/Commission')       AS CMMSN1
,   EXTRACTVALUE(xseq.column_value, '/Employee/EmpPayment/Commissions/CommissionByMonth[2]/Commission')       AS CMMSN2
,   EXTRACTVALUE(xseq.column_value, '/Employee/EmpPayment/Commissions/CommissionByMonth[3]/Commission')       AS CMMSN3
,   EXTRACTVALUE(xseq.column_value, '/Employee/EmpPayment/Commissions/CommissionByMonth[4]/Commission')       AS CMMSN4
FROM   xml_stg_tbl do
,  TABLE(XMLSEQUENCE(EXTRACT(VALUE(do), '/Employees/Employee'))) xseq

The XML node values are displayed as column val in the view. In the view I am selecting the column "CMMSNASOFM1", CMMSNASOFM2 etc based on the position of the node.
column CMMSN1, CMMSN2 will have value corresponding to CMMSNASOFM1, CMMSNASOFM2 respectively.

In xml nodes at "Employees/Employee/EmpPayment/Commissions/CommissionByMonth" might be in different order. now the view which gets the value based on position of the nodes "CommissionByMonth".

If the xml file node value at CommissionByMonth/AsOfMonthEnd is not in proper order, the view columns gets the value "as is" from the xml.

I would like to sort the xml nodelist "Employees/Employee/EmpPayment/Commissions/CommissionByMonth" based on "AsOfMonthEnd" col value and then refer the columns by the position in view.

For example,
AsOfMonthEnd (node 1) has apr2010 commision and AsOfMonthEnd(node 2) has jan2010 commision, the view's CMMSNASOFM1 will have apr2010 as its value and CMMSNASOFM2 will have jan2010 value.

I would like to sort the CommissionByMonth/AsOfMonthEnd and then output the value in view as CMMSNASOFM1 = jan2010 and CMMSNASOFM2=apr2010
CMMSN1=commission as of jan2010
CMMSN2=commission as of apr2010

Could somebody guide me how to get this nodelist sorted and get the value thro oracle view.

Thanks
Arnee
Attachments:
 
sample xml file
 

Answer : Read XML through oracle view and ordered output

Instead of:
    var parentTxt = $(this).parent('span.folder').text();

use:
 var parentTxt = $('span.folder', $(this).closest("ul").parent() ).text();

which basically states:
look for span.folder WITHIN $(this).closest("ul").parent().

If you take a closer look at your markup, it should be clear that when you click on Search, $(this).closest("ul") refers to <ul id="test"> and its parent is the li that contains both, <ul id="test"> AND <span class="folder">.

So essentially this:
$(this).closest("ul").parent()

refers to the first <li> in <ul id="treemenu">. So, to summarize:

$('span.folder', $(this).closest("ul").parent() ).text();
says:
look for span.folder within the li in <ul id="treemenu">
Clear?
Random Solutions  
 
programming4us programming4us