parsing an xml file with attributes only

i would like to contribute an example of parsing an only attributes xml file using $replace it is valid for version 8 and up . MY WAY IS CONVERT THE FILE TO LISTS WITH GOLD + ; AS SEPRATOR the outcome can easyly handle with the uniface list statements

The  unicode xml file  ProdReport.xml
<?xml version=”1.0″ encoding=”unicode” standalone=”yes”?>
<prodOrder lineID=”Line5″ id=”34641″ startTime=”2004-12-08 02:41:38″ endTime=”2004-12-09 15:46:27″>
<accum contents=”0000″ type=”KG    ” unitID=”KG    ” amount=”0.000″ startTime=”2004-12-08 02:41:38″ endTime=”2004-12-09 5:46:27″/>
<accum contents=”011204″ type=”KG    ” unitID=”KG    ” amount=”813.702″ startTime=”2004-12-08 02:41:38″ endTime=”2004-12-09 15:46:27″ />
<accum contents=”011300″ type=”KG    ” unitID=”KG    ” amount=”206.789″ startTime=”2004-12-08 02:41:38″ endTime=”2004-12-09 15:46:27″ />
<accum contents=”024000″ type=”KG    ” unitID=”KG    ” amount=”3.457″ startTime=”2004-12-08 02:41:38″ endTime=”2004-12-09 15:46:27″ />
<accum contents=”024007″ type=”KG    ” unitID=”KG    ” amount=”5.229″ startTime=”2004-12-08 02:41:38″ endTime=”2004-12-09 15:46:27″ />
<accum contents=”024011″ type=”KG    ” unitID=”KG    ” amount=”6.909″ startTime=”2004-12-08 02:41:38″ endTime=”2004-12-09 15:46:27″ />
</prodOrder>

the code to parse it

===============
fileload “c:\ProdReport.xml”,$string2file$

scan l_file.fh_write ,“<prodOrder”

l_file.fh_write = l_file.fh_write[$result]
l_file.fh_write=
$replace ( l_file.fh_write , 1 ,“=%%”” , “=”,-1)
l_file.fh_write=
$replace ( l_file.fh_write , 1 ,“%%”%%% ” , “%%”%%%·;”,-1)
l_file.fh_write=
$replace ( l_file.fh_write , 1 ,“<prodOrder ” , “%%””,-1)
l_file.fh_write=
$replace ( l_file.fh_write , 1 ,”  <accum ” , “%%””,-1)
l_file.fh_write=
$replace ( l_file.fh_write , 1 ,“·;” , “·;%%””,-1)
l_file.fh_write=
$replace ( l_file.fh_write , 1 ,“·;%%”/>”,“” ,-1)
l_file.fh_write=
$replace ( l_file.fh_write , 1 ,“</prodOrder>”,“” ,-1)
l_file.fh_write=
$replace ( l_file.fh_write , 1 ,“>”,“” ,-1)
; filedump 
l_file.fh_write , “c:\avner.txt”

the result data is

============================


“lineID=Line5″·;”id=34641″·;”startTime=2004-12-08 02:41:38″·;”endTime=2004-12-09 15:46:27”
“contents=0000″·;”type=KG    “·;”unitID=KG    “·;”amount=0.000″·;”startTime=2004-12-08 02:41:38″·;”endTime=2004-12-09 15:46:27”
“contents=011204″·;”type=KG    “·;”unitID=KG    “·;”amount=813.702″·;”startTime=2004-12-08 02:41:38″·;”endTime=2004-12-09 15:46:27”
“contents=011300″·;”type=KG    “·;”unitID=KG    “·;”amount=206.789″·;”startTime=2004-12-08 02:41:38″·;”endTime=2004-12-09 15:46:27”
“contents=024000″·;”type=KG    “·;”unitID=KG    “·;”amount=3.457″·;”startTime=2004-12-08 02:41:38″·;”endTime=2004-12-09 15:46:27”
“contents=024007″·;”type=KG    “·;”unitID=KG    “·;”amount=5.229″·;”startTime=2004-12-08 02:41:38″·;”endTime=2004-12-09 15:46:27”
“contents=024011″·;”type=KG    “·;”unitID=KG    “·;”amount=6.909″·;”startTime=2004-12-08 02:41:38″·;”endTime=2004-12-09 15:46:27”

 

0 thoughts on “parsing an xml file with attributes only”

  1. Hi avner,
    nice example how to survive without an XML reader. I suggest 2 modifications: 1 treat each XML element as a list-in-list using GOLD! in front of the GOLD; and drop the Quotes in the list so we can use the $item function. Success, Uli P.S. when I am back from my bread-and-water REHA, i will provide an example (I hope I am released in three weeks time)

Leave a Reply