‎2006 Dec 30 12:22 PM
I have an XML document and i need to order certains elements .
My XML document is like this
<doc number = '12343401'>John Smith</doc>
<BEHs>
<BEH id = '04'>2000</BEH>
<BEH id = '02'>200</BEH>
<BEH id = '03'>1230</BEH>
<BEH id = '01'>223</BEH>
</BEHs>
</doc>
I need to order BEH elements using id attribute
‎2007 Jan 03 8:55 AM
you receive this xml from some other source or your program creates this ?
in general to sort a XML document you need to use XSLT program command xsl:sort ,
in your case you need to create a xslt program and use it with call transformation to sort your xml file.
Regards
Raja
‎2007 Jan 03 8:55 AM
you receive this xml from some other source or your program creates this ?
in general to sort a XML document you need to use XSLT program command xsl:sort ,
in your case you need to create a xslt program and use it with call transformation to sort your xml file.
Regards
Raja
‎2007 Jan 03 6:50 PM
‎2007 Oct 21 10:18 AM
It's impossible to sort an XML in version 4.6 but you can sort in ECC 6.0 with XSLT and sort command
‎2007 Oct 21 6:34 PM
Of course XSLT would be technique of choice if it would be available. The really cool hacker solution of course wouuld be building your own XSLT / XPATH implementation in abap for 4.6- but sometimes the quick and dirty solution is the better choice. In the end if the XML is not to structured / complex it's just a bit hack and slay or SPLIT and CONCATENATE ;o)
DATA:
lv_xml_old TYPE string,
lv_xml_new TYPE string,
ln_beg TYPE i,
ln_end TYPE i,
ln_len TYPE i,
lv_buff TYPE string,
lt_buff TYPE TABLE OF string.
CONCATENATE
'<doc number = ''12343401''>John Smith</doc>'
'<BEHs>'
'<BEH id = ''04''>2000</BEH>'
'<BEH id = ''02''>200</BEH>'
'<BEH id = ''03''>1230</BEH>'
'<BEH id = ''01''>223</BEH>'
'</BEHs>'
'</doc>'
INTO
lv_xml_old.
REPLACE ALL OCCURRENCES OF '''' IN lv_xml_old WITH '"'.
FIND FIRST OCCURRENCE OF '<BEHs>' IN lv_xml_old MATCH OFFSET ln_beg.
FIND FIRST OCCURRENCE OF '</BEHs>' IN lv_xml_old MATCH OFFSET ln_end.
ln_beg = ln_beg + 6.
ln_len = ln_end - ln_beg.
SPLIT lv_xml_old+ln_beg(ln_len) AT '</BEH>' INTO TABLE lt_buff.
SORT lt_buff.
lv_xml_new = lv_xml_old(ln_beg).
LOOP AT lt_buff INTO lv_buff.
CONCATENATE
lv_xml_new
lv_buff
'</BEH>'
INTO
lv_xml_new.
ENDLOOP.
CONCATENATE
lv_xml_new
lv_xml_old+ln_end
INTO
lv_xml_new.
REPLACE ALL OCCURRENCES OF '"' IN lv_xml_new WITH ''''.
WRITE lv_xml_new.
hf
Roman
‎2007 Oct 25 8:20 PM