Author |
Message
|
djosyula |
Posted: Thu Apr 27, 2017 6:16 am Post subject: ESQL coding for sorting of data from XML input |
|
|
Newbie
Joined: 30 Mar 2017 Posts: 9
|
Hi Experts , Is there any way in ESQL coding for sorting of data from XML file.Thanks in advance
input :
<LIST>
<EMP>
<EMP_ID>4</EMP_ID>
</EMP>
<EMP>
<EMP_ID>3</EMP_ID>
</EMP>
<EMP>
<EMP_ID>1</EMP_ID>
</EMP>
<EMP>
<EMP_ID>2</EMP_ID>
</EMP>
</LIST>
Expecting output :
<LIST>
<EMP>
<EMP_ID>1</EMP_ID>
</EMP>
<EMP>
<EMP_ID>2</EMP_ID>
</EMP>
<EMP>
<EMP_ID>3</EMP_ID>
</EMP>
<EMP>
<EMP_ID>4</EMP_ID>
</EMP>
</LIST> |
|
Back to top |
|
 |
mpong |
Posted: Thu Apr 27, 2017 8:25 pm Post subject: |
|
|
Disciple
Joined: 22 Jan 2010 Posts: 164
|
What did you try so far ? |
|
Back to top |
|
 |
timber |
Posted: Fri Apr 28, 2017 1:18 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Use the Search button and search for the word 'sorting'. |
|
Back to top |
|
 |
djosyula |
Posted: Wed May 03, 2017 5:56 am Post subject: sorting in esql is done |
|
|
Newbie
Joined: 30 Mar 2017 Posts: 9
|
Here is code for sorting in ESQL
DECLARE SIZE INTEGER CARDINALITY(InputRoot.XMLNSC.LIST.*[]);
DECLARE rOutRef REFERENCE TO OutputRoot.XMLNSC;
DECLARE I,J INTEGER 1;
DECLARE A ,TEMP_F,TEMP_S,TEMP_SWITCH INTEGER;
SET OutputRoot.XMLNSC.aj.ARRAY[]=InputRoot.XMLNSC.LIST.EMP[];
WHILE J<=SIZE-1 DO
WHILE SIZE >I DO
SET TEMP_F=OutputRoot.XMLNSC.aj.ARRAY[I].EMP_ID;
SET TEMP_S=OutputRoot.XMLNSC.aj.ARRAY[I+1].EMP_ID;
IF TEMP_F>TEMP_S THEN
SET TEMP_SWITCH=OutputRoot.XMLNSC.aj.ARRAY[I].EMP_ID;
SET OutputRoot.XMLNSC.aj.ARRAY[I].EMP_ID=OutputRoot.XMLNSC.aj.ARRAY[I+1].EMP_ID;
SET OutputRoot.XMLNSC.aj.ARRAY[I+1].EMP_ID=TEMP_SWITCH;
END IF;
--SET A = SELECT MIN(t.EMP_ID) from OutputRoot.XMLNSC.aj.ARRAY[] as t;
--SET OutputRoot.XMLNSC.aj.ARRAY[A]=NULL;
SET I =I+1;
END WHILE;
SET J=J+1;
SET I=1;
END WHILE;
RETURN TRUE; |
|
Back to top |
|
 |
timber |
Posted: Wed May 03, 2017 7:29 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
If you post code, please use code tags.
I would not recommend doing the sorting using ESQL; Java is likely to be a lot faster and you don't have to write the sorting algorithm yourself ( although you do need to do some work to understand how Java collection classes work ). |
|
Back to top |
|
 |
|