ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Parsing XML with RPGLE.

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Parsing XML with RPGLE.

    Hi Guys,

    I got some great advice with my previous question (See Here).

    I am still working on the same project but now I need to "import" forex data into my database. The project is for non-profit purposes, its like a mini graduation project for the IBM Academic Initiative.

    My Problem:
    I need to parse an XML into my DB, but I think my DS is not correct.

    My Request:
    Please help me to import the XML into my DB, I believe my issue is with the DataStructure. Though I don't know what I am doing wrong.

    Further Info:
    I have found and very nice source for forex data from the ECB (European Central Bank). They say I can use their data when "ECB must be cited as the source."

    I have edited the ECB xml file to only have 2 day's forex info, as I do not just to get the XML-INTO program I am writing to work.
    Please find it attached as F1.xml

    Changes in my opinion I needed to make some changes to the original ECB xml,
    as the was ":" and duplicate tags.
    Code:
    [B]From:[/B]                      [B]To:[/B]
    gesmes:Envelope		gesmesEnvelope
    gesmes:subject		gesmesSubject
    gesmes:Sender		gesmesSender
    gesmes:name		gesmesName
    Cube time		CubeT time
    Cube currency		CubeCur currency
    
    The last /Cube needs not be changed the rest must be /CubeT
    My RPGLE (FxRatesXML.rpgle):
    Code:
          // The Purpose of this program is to parse an xml file form ECB bank
          // The xml file contains 90 days worth of Forex Rates
          // The xml's (unedited) is obtainable from:
          // http://www.ecb.europa.eu/stats/exchange/eurofxref/html/index.en.html
    
         FFXRATES   UF A E           K Disk
    
         DgesmesEnvelope   Ds                  Qualified
         D xmlnsGesmes                   40A
         D xmlns                         50A
         D gesmesSubject                 20A
         D gesmesSender                        LikeDS(gesmesSender)
         D Cube                                LikeDS(Cube)
    
         D gesmesSender    Ds                  Qualified
         D   gesmesName                  20A
    
         D Cube            Ds                  Qualified
         D  CubeT                              LikeDS(CubeT) Dim(90)                 //Prov for 90 Days
    
         D  CubeT          Ds                  Qualified
         D   time                          D
         D   CubeCur                           LikeDS(CubeCur) Dim(34)              //Prov for 34 Currencies
    
         D   CubeCur       Ds                  Qualified
         D     currency                   3A
         D     rate                       9P 4
    
         D XML_Source      S            256A   Varying
         D                                     Inz('/home/OL20007/Christoff/F1.xml')
    
         D CURSYMFROM      S              3A   Inz('EUR')
         D CURSYMTO        S              3A   Inz(*HiVal)
         D RATE            S              9P 4 Inz(*HiVal)
    
         D X               S              3P 0
         D Y               S              3P 0
    
          /Free
    
           //Read the XML into a mega DS
           XML-INTO gesmesEnvelope %XML(XML_Source: 'doc=file +
                                                     case=any +
                                                     allowmissing=yes');
           //Process the mega DS and update the database
           //For the Days 1 to 90
           For X = 1 to 90;
             gesmesEnvelope.Cube.CubeT(X).time = CURDATE;
    
             //If there is no Date in the XML file do not process or update DB
             IF NOT (CURDATE = *HiVal);
    
              //For the 34 Currencies
              For Y = 1 to 34;
                gesmesEnvelope.Cube.CubeT(X).CubeCur(Y).currency = CURSYMTO;
                gesmesEnvelope.Cube.CubeT(X).CubeCur(Y).rate = RATE;
    
                //IF there is no Currency info for the date, do not process.
                IF NOT (CURSYMTO = *HiVal) or (RATE = *HiVal);
                  Chain (CURDATE:CURSYMFROM:CURSYMTO) FXRATES;
                  If NOT %Found(FXRATES);
                    Update FXRATESREC;
                  ENDIF;
                ENDIF;
    
                //Reset the CurSymTO and the Rate variables to *HiVal
                Reset CURSYMTO;
                Reset RATE;
              ENDFOR;
    
             ENDIF;
             //Reset the CurDate var to *HiVal
             Reset CURDATE;
           ENDFOR;
           *Inlr = *On;
           Return;
    
          /End-Free
    My Databse (FxRates.pf) (Another Tx to Philippe and Michael)
    Code:
         A**************************************************************************
         A*** Database of the Currencies
         A**************************************************************************
         A                                      UNIQUE
         A          R FXRATESREC
         A            CURDATE         L         TEXT('Date of the Currency Row')
         A            CURSYMFROM     3A         TEXT('Convert From Currency Code')
         A            CURSYMTO       3A         TEXT('Convert To Currency Code')
         A            RATE           9P 4       TEXT('Conversion Multiplier')
         A**************************************************************************
         A          K CURDATE
         A          K CURSYMFROM
         A          K CURSYMTO
    Attached Files

  • #2
    Re: Parsing XML with RPGLE.

    What do you get in the gesmesEnvelope DS before setting LR on ?

    Why don't you write the record instead ?
    Philippe

    Comment


    • #3
      Re: Parsing XML with RPGLE.

      Originally posted by Mercury View Post
      What do you get in the gesmesEnvelope DS before setting LR on ?
      I get "Error message CPF4203 appeared during OPEN for file FXRATES", so I need to STRDBG PGM(FXRATESXML) UPDPROD(*YES)

      When I debug the pgm I get the following error "The XML parser detected error code 5. Unmonitored exception at line 42".
      With Line 42 being the XML-INTO statement.

      I tried to google: XML-INTO parser "error code 5", but got no answers.

      Please find attached the "Dump" for the pgm and DS's as requested.

      Why don't you write the record instead ?
      Thanks for the tip, Updated the update to be right as in Write.
      Attached Files

      Comment


      • #4
        Re: Parsing XML with RPGLE.

        Hello,

        The information you're looking for is at http://publib.boulder.ibm.com/infoce...c092507216.htm
        It says "The start and end tag names of an element did not match."
        The xml file you joined to your first post seems well-formed, i checked it against Notepad++xml validation tool, So maybe the file you use is not the exact file you sent, or you have a CCSID problem.
        Since the DS is filled with information from gesmesSubject and gesmesSender but not further, i suggest you look at the first CubeT end tag

        ps: i think
        Code:
                 gesmesEnvelope.Cube.CubeT(X).time = CURDATE;
        should be
        Code:
                 CURDATE = gesmesEnvelope.Cube.CubeT(X).time;
        and same for rate and cursymto
        Nicolas

        Comment


        • #5
          Re: Parsing XML with RPGLE.

          Unless you are running V7 you cannot handle namespaces with XML-INTO. i.e. the gesmes: part of the element names. So you are correct that you need to edit the original file. For the sake of this example I have simply stripped it off.

          So the XML looks like this:
          PHP Code:
          <Envelope>
              <
          subject>Reference rates</subject>
              <
          Sender>
                  <
          name>European Central Bank</name>
              </
          Sender>
              <
          Cube>
                  <
          Cube time="2011-06-22">
                      <
          Cube currency="USD" rate="1.4397" />
                      <
          Cube currency="JPY" rate="115.36" />
                      <
          Cube currency="BGN" rate="1.9558" /> 
          For this the DS looks like this:

          PHP Code:
               d Envelope        DS                  Qualified
               d   subject                     40a
               d   Sender                            LikeDS
          (Sender_T)
               
          d   Cube                              LikeDS(Cube_T)
               
          d
               d Sender_T        DS                  Template
               d   name                        40a
               d
               d Cube_T          DS                  Template Qualified
               d   time                        10a
               d   Cube                              LikeDS
          (Cube2_T)
               
          d
               d Cube2_T         DS                  Template Qualified
               d   Cube                              Dim
          (100)
               
          d                                     LikeDS(Cube3_T)

               
          d Cube3_T         DS                  Template
               d   currency                     3a
               d   rate                        20a 
          If you don't want the Envelope, subject etc. you could use a path directive with the XML-INTO to put it down to the start of the repeating cube element. If you did that allowmissing=yes wouldn't be needed as the xml elements count supplied by the compiler would do the job for you.

          I haven't time to test this for you but hopefully it will show you the right direction.

          Your exchange rates would be referenced like this:

          Code:
                /Free
                 If Envelope.Cube.Cube.Cube(1).currency = 'USD';
                   Envelope.Cube.Cube.Cube(1).rate = 'Horribly low'; 
                 EndIf;
          Hope this helps - and I hope one day you can meet the guy who came up with the idiotic cube.cube.cube nesting and give him a good kicking in the rear end!

          Comment


          • #6
            Re: Parsing XML with RPGLE.

            Originally posted by JonBoy View Post
            Unless you are running V7 you cannot handle namespaces with XML-INTO.
            Wasn't the namespace enhancement for xml made available via PTF for 6.1 either (PTF SI42426)?

            Birgitta

            Comment


            • #7
              Re: Parsing XML with RPGLE.

              You are correct Birgitta - brain not fully engaged this morning! I was too focussed on the DS structure.

              I wrote about the darn thing so I should have remembered! http://www.ibmsystemsmag.com/ibmi/de...oved-XML-INTO/

              Comment


              • #8
                Re: Parsing XML with RPGLE.

                Originally posted by JonBoy View Post
                Code:
                /Free
                If Envelope.Cube.Cube.Cube(1).currency = 'USD';
                Envelope.Cube.Cube.Cube(1).rate = 'Horribly low'; 
                EndIf;
                I see you used current USD valuations in your example.

                And if I had to parse the file to fix the name spaces, I would probably be tempted to go ahead and fix the ridiculous cube issue as well.
                Michael Catalani
                IS Director, eCommerce & Web Development
                Acceptance Insurance Corporation
                www.AcceptanceInsurance.com
                www.ProvatoSys.com

                Comment


                • #9
                  Re: Parsing XML with RPGLE.

                  Gonna Keep my Rely short and sweet:

                  I got the XML to parse!!!!

                  Thanks to all that assisted me with getting XML to parse, I really appreciate your input. With out your pointers I could not have done this.

                  Also thank you for the xml hyperlinks above, I they are on my reading list.


                  Below is my Fx Conversion Pgm. Feel Free use and modify it as you need.
                  There are many ways to skin a cat, this is mine!

                  The PF (FXRATES.pf):
                  Code:
                       A**************************************************************************
                       A*** Database of the Currencies to be queried by the program
                       A**************************************************************************
                       A                                      UNIQUE
                       A          R FXRATESREC
                       A            CURDATE         L         TEXT('Date of the Currency Row')
                       A            CURSYMFROM     3A         TEXT('Convert From Currency Code')
                       A            CURSYMTO       3A         TEXT('Convert To Currency Code')
                       A            RATE           9P 4       TEXT('Conversion Multiplier')
                       A**************************************************************************
                       A          K CURDATE
                       A          K CURSYMFROM
                       A          K CURSYMTO
                  My Parsing Pgm (FXRATESXML):
                  Code:
                        // The Purpose of this program is to parse an xml file form ECB bank
                        // The xml file contains 90 days worth of Forex Rates
                        // The xml's (unedited) is obtainable from:
                        // http://www.ecb.europa.eu/stats/exchange/eurofxref/html/index.en.html
                  
                       FFXRATES   UF A E           K Disk
                  
                        //DgesmesEnvelope   Ds                  Qualified
                        //D xmlnsGesmes                   40A
                        //D xmlns                         50A
                        //D gesmesSubject                 20A
                        //D gesmesSender                        LikeDS(gesmesSender)
                        //D Cube                                LikeDS(Cube)
                  
                        //D gesmesSender    Ds                  Qualified
                        //D   gesmesName                  20A
                  
                       D Cube            Ds                  Qualified
                       D  CubeT                              LikeDS(CubeT) Dim(90)                //Prov for 3 Days
                  
                       D  CubeT          Ds                  Qualified Template
                       D   time                        10A
                       D   CubeCur                           LikeDS(CubeCur) Dim(34)              //Prov for 34 Curren
                  
                       D   CubeCur       Ds                  Qualified Template
                       D     currency                   3A
                       D     rate                      10A
                  
                       D XML_Source      S            256A   Varying
                       D                                     Inz('/home/OL20007/Christoff/F1.xml')
                  
                       D X               S              3P 0
                       D Y               S              3P 0
                  
                        /Free
                  
                         //Initialise Variable to HiVal, so that only "changes" are uploaded to DB
                         CURSYMFROM = 'EUR';
                         CURSYMTO   = *HiVal;
                         RATE       = *HiVal;
                  
                         //Read the XML into a mega DS
                         XML-INTO Cube %XML(XML_Source: 'doc=file +
                                                         case=any +
                                                         allowmissing=yes');
                         //Process the mega DS and update the database
                         //For the Days 1 to 90
                         For X = 1 to 90;
                           //If there is no Date in the XML file do not process or update DB
                           IF NOT (Cube.CubeT(X).time = *Blanks);
                             CURDATE = %Date(Cube.CubeT(X).time:*ISO);
                  
                            //For the 34 Currencies
                            For Y = 1 to 34;
                               //IF there is no Currency info for the date, do not process.
                              IF    (Cube.CubeT(X).CubeCur(Y).currency <> *Blanks)
                                 OR (Cube.CubeT(X).CubeCur(Y).rate <> *Blanks);
                  
                                CURSYMTO = Cube.CubeT(X).CubeCur(Y).currency;
                                RATE     = %Dec(Cube.CubeT(X).CubeCur(Y).rate:9:4);
                  
                                Chain (CURDATE:CURSYMFROM:CURSYMTO) FXRATES;
                                 If NOT %Found(FXRATES);
                                   Write FXRATESREC;
                                 ENDIF;
                              ENDIF;
                            ENDFOR;
                           ENDIF;
                         ENDFOR;
                  
                         *Inlr = *On;
                         Return;
                  
                        /End-Free
                  My Display PGM (FOREXRGLE.rpgle):
                  Code:
                         //*****************************************************************
                         //*****************************************************************
                         //PCCD
                         // Purpose: Currency Conversion Program
                         //          To allow user to interactively query forex translations
                         // Created by: Christoff Erasmus 
                         // Date: 15 June 2011
                         //*****************************************************************
                         //*************************************************************** H Specs
                  
                         //*************************************************************** F Specs
                          //Input List of Currencies available and their names
                       FFXCURLIST IF   E           K DISK
                  
                          //Forex Conversion Rates Database
                       FFXRATES   IF   E           K DISK
                  
                          //Display file used to interact with user
                       FFOREXDSPF CF   E             Workstn Sfile(SFL1:Rrn)
                       F                                     Indds(Indicators)
                  
                         //*************************************************************** D Specs
                          //------------------------------------------------- Main procedure PR/PI
                       D Main            PR                  Extpgm('FOREXRPGLE')
                       D Main            PI
                  
                          //----------------------------------------------------------- Prototypes
                          //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Procedure Prototypes
                  
                          //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Called Program Prototypes
                  
                          //-------------------------------------------- DataStructures and Arrays
                           //Display File Indicator data structure
                       D Indicators      Ds
                       D  Exit                   3      3N
                       D  ListCurrency           4      4N
                       D  Cancel                12     12N
                       D  SflClr                50     50N
                       D  SflDsp                51     51N
                       D  DspCancel             91     91N
                       D  DspFxLstPmpt          92     92N
                  
                          //------------------------------------------------------Global Variables
                       D Rrn             S              2P 0
                       D OPT             S              1A   Inz(*Blank)
                       D BASERATE        S              9P 4
                  
                         //***********************************************************Main Program
                        /Free
                         QRYDATE      = %Date('2011-01-01');
                         BASECUR      = 'ZAR';
                         BASEAMNT     = 999.00;
                         QRYCUR       = 'USD';
                         DspCancel    = *On;
                         DspFxLstPmpt = *On;
                         Reset Message;
                  
                         Dow NOT Exit;
                           Exsr MainScrn;
                                  //Check if Exit or Cancel is signaled
                                    Select;
                                     When Exit;
                                          Leave;
                                     When Cancel;
                                          Cancel = *Off;
                                          //Leave;
                                    ENDSL;
                  
                           Reset Message;
                  
                           SELECT;
                  
                             //When F3 is pressed, exit the program
                             WHEN Exit;
                               Leave;
                  
                             //When F4 is pressed, display currency selection screen
                             WHEN ListCurrency;
                               Exsr CurListScrn;
                                              //Check if Exit or Cancel is signaled
                                              Select;
                                                When Exit;
                                                  Leave;
                                                When Cancel;
                                                  Cancel = *Off;
                                                  //Leave;
                                              ENDSL;
                  
                             //Lookup Conversion Rate and Perform the conversion, then display result screen
                             OTHER;
                                  //As the RatesDB is Eur based.
                                  // All Rates must be Converted to EUR before translation to
                                  // another currency.
                  
                               Chain (QryDate:'EUR':BASECUR) FXRATES;
                                IF %Found(FXRATES);
                                  BASERATE = RATE;
                                  Chain (QryDate:'EUR':QRYCUR) FXRATES;
                                    IF %Found(FXRATES);
                                      RATE = (RATE/BASERATE);
                                      RESULTAMNT  = RATE * BASEAMNT;
                  
                                      ScreenID     = 'Result';
                                      DspFxLstPmpt = *Off;
                                      DspCancel    = *On;
                                      Write Heading;
                                      Write Footer;
                                      Exfmt RECORD2;
                                              //Check if Exit or Cancel is signaled
                                              Select;
                                                When Exit;
                                                  Leave;
                                                When Cancel;
                                                  Cancel = *Off;
                                                  //Leave;
                                              ENDSL;
                                    ELSE;
                                      Message = 'Currency to Query not found, F4 select another';
                                    ENDIF;
                                ELSE;
                                  Message = 'Base Currency not found, F4 select another';
                                ENDIF;
                           ENDSL;
                         ENDDO;
                  
                         *Inlr = *On;
                         Return;
                  
                         //*********************************************************** Subroutines
                         //#############################################################  MainScrn
                         BegSr MainScrn;
                           //Display Main Selection Screen and wait for user input
                           SCREENID = 'Main';
                           DspFxLstPmpt = *On;
                           DspCancel    = *Off;
                           Write Heading;
                           Write Footer;
                           Exfmt Record1;
                         ENDSR;
                  
                         //########################################################### CurListScrn
                         BegSr CurListScrn;
                           SCREENID = 'CURLIST';
                           DspFxLstPmpt = *Off;
                           DspCancel    = *On;
                           Write Heading;
                           Write Footer;
                  
                           Exsr Clear_Subfile;
                           Exsr Load_Subfile;
                           Exsr Display_Subfile;
                         ENDSR;
                  
                         //######################################################### Clear_Subfile
                         BegSr Clear_Subfile;
                           SflClr = *On;
                           SflDsp = *Off;
                           Rrn = *Zeros;
                  
                           Write CTL1;
                  
                           SflClr = *Off;
                           SflDsp = *On;
                         ENDSR;
                  
                         //########################################################## Load_Subfile
                         BegSr Load_Subfile;
                           Setll *LoVal FXCURLIST;
                           Read FXCURLIST;
                           Dow Not %Eof(FXCURLIST);
                             Rrn += 1;
                             Write SFL1;
                             Read FXCURLIST;
                           ENDDO;
                           SflDsp = (Rrn > 0);
                         ENDSR;
                  
                         //####################################################### Display_Subfile
                         BegSr Display_Subfile;
                             Clear OPT;
                             Clear Message;
                  
                           DoW Not (Exit or Cancel or OPT<>*Blank);
                             Exfmt CTL1;
                                  //Check if Exit or Cancel is signaled
                                    Select;
                                     When Exit;
                                          Leave;
                                     When Cancel;
                                          Cancel = *Off;
                                          Leave;
                                    ENDSL;
                             Clear Message;
                             Readc SFL1;
                  
                             SELECT;
                               When (OPT = *Blank) or (%Eof);
                                 Message = 'Please make a selection';
                               When FLD = 'BASECUR';
                                 BASECUR = CURSYM;
                                 Clear FLD;
                                 Clear OPT;
                                 Leave;
                               When FLD = 'QRYCUR';
                                 QRYCUR = CURSYM;
                                 Clear FLD;
                                 Clear OPT;
                                 Leave;
                             ENDSL;
                  
                           ENDDO;
                           Reset Message;
                         ENDSR;
                  
                        /End-Free
                  My Display File (FOREXDSPF.dspf):
                  Code:
                       A                                      REF(FXCURLIST)
                       A                                      PRINT
                       A                                      INDARA
                       A**************************************************************************
                       A***Heading Record
                       A          R HEADING                   OVERLAY
                       A                                  1 70DATE(*JOB *YY)
                       A                                      EDTCDE(Y)
                       A                                  2 63'ScreenID:'
                       A            SCREENID       7A  O  2 73
                       A                                  1 26'IBM Academic Initiative (Project)'
                       A                                  2 28'Created by Christoff Erasmus'
                       A***Footer Record
                       A          R FOOTER                     OVERLAY
                       A                                 23  3'F3=Exit'
                       A  91                             23 11'F12=Cancel'
                       A  92                             23 22'F4=Currency List'
                       A            MESSAGE       70   O 24  6DSPATR(HI)
                       A**************************************************************************
                       A*** Main Screen, used to obtain user input and currency selection
                       A          R RECORD1                   OVERLAY
                       A                                      CA03(03 'F3=EXIT')
                       A                                      CA04(04 'F4=Currency List')
                       A                                      RTNCSRLOC(&RCD &FLD)
                       A            FLD           10A  H
                       A            RCD           10A  H
                       A                                  6  2'Currency Exchange Rate Query:'
                       A                                  7 21'Base Currency . . .'
                       A            BASECUR        3X  B  7 41CHECK(MF)
                       A                                  8 21'Base Amount . . . .'
                       A            BASEAMNT       9Y 2B  8 41EDTWRD(' ,   ,   .  ')
                       A                                      EDTMSK(' &   &   &  ')
                       A                                  9 21'Currenty to Query .'
                       A            QRYCUR         3A  B  9 41CHECK(MF)
                       A                                 12  2'Press Enter for the Result'
                       A                                 10 21'Query Date. . . . .'
                       A            QRYDATE         L  B 10 41
                       A**************************************************************************
                       A*** Result Screen, used to display the result of the Forex conversion
                       A          R RECORD2                   OVERLAY
                       A                                      CA03(03 'F3=EXIT')
                       A                                      CA12(12 'F12=Cancel')
                       A                                  6  2'Currency Exchange Rate Query:'
                       A                                  9 21'Base Currency . . .'
                       A            BASECUR        3A  O  9 41
                       A                                 10 21'Base Amount . . . .'
                       A                                  7 21'Query Date. . . . .'
                       A            QRYDATE         L  O  7 41
                       A            BASEAMNT       9Y 2O 10 41EDTCDE(2)
                       A                                 12 21'Conversion Rate:. .'
                       A            RATE           9Y 4O 12 41EDTCDE(2)
                       A                                 14 21'Result Currenty'
                       A            QRYCUR         3A  O 14 41
                       A                                 15 21'Result Amount'
                       A            RESULTAMNT     9Y 2O 15 41EDTWRD(' ,   ,   .  ')
                       A                                 17  1'Press Enter to return.'
                       A**************************************************************************
                       A** Subfile to display a list of available currencies. For user selection
                       A****Record format for subfile
                       A          R SFL1                      SFL
                       A            OPT            1   B  6  4
                       A            CURSYM         3A  O  6 12
                       A            CURNAME       20A  O  6 21
                       A****Record format for subfile CONTROL
                       A          R CTL1                      SFLCTL(SFL1)
                       A  51                                  SFLDSPCTL
                       A  51                                  SFLDSP
                       A  50                                  SFLCLR
                       A                                      SFLPAG(15)
                       A                                      SFLSIZ(35)
                       A                                      OVERLAY
                       A                                      CA03(03 'F3=EXIT')
                       A                                      CA12(12 'F12=Cancel')
                       A                                  4  4'Listing of Currencies available:'
                       A                                  5  4'Option'
                       A                                  5 12'Symbol'
                       A                                  5 21'Name'
                  
                  
                       A*%%RS+
                       A*%%RS+ 
                       A*%%RS+  
                       A*%%RS+  
                       A*%%RS+  
                       A*%%RS+  
                       A*%%RS+ 
                       A*%%RS+ 
                       A*%%RS+  
                       A*%%RS+  
                       A*%%RS+  
                       A*%%RS+  
                       A*%%RS+ 
                       A*%%RS+ 
                       A*%%RS+  
                       A*%%RS+  
                       A*%%RS+  
                       A*%%RS+  
                       A*%%RS+  
                       A*%%RS+ 
                       A*%%RS 
                  And the Currency List DB (FXCURLIST.pf):
                  Code:
                       A**************************************************************************
                       A*** Database to List the Currencies Supported by the program
                       A*** Created by Christoff Erasmus on 14 June 2011
                       A*** Email: 
                       A**************************************************************************
                       A                                      UNIQUE
                       A          R CURLSTREC
                       A            CUR#           3S 0       TEXT('CUR#')
                       A            CURSYM         3A         TEXT('Currency Symbol')
                       A            CURNAME       20A         TEXT('Currency Name')
                       A          K CUR#
                  Program to Populate the Currency List Date Base (FOREXDBFIL):
                  Code:
                        // Quick pgm to written to populate FXCURLIST datebase
                        // Written by Christoff Erasmus on 14 June 2011
                        // Email: 
                  
                       FFXCURLIST UF A E           K DISK
                  
                       D CURARRAY        S             25A   Dim(34)
                       D X               S              2  0
                  
                        /Free
                  
                          //Listing of Currencies
                         CURARRAY(1)  = 'AUD Australian dollar';
                         CURARRAY(2)  = 'BGN Bulgarian lev';
                         CURARRAY(3)  = 'BRL Brazilian real';
                         CURARRAY(4)  = 'CAD Canadian dollar';
                         CURARRAY(5)  = 'CHF Swiss franc';
                         CURARRAY(6)  = 'CNY Chinese yuan renminbi';
                         CURARRAY(7)  = 'CZK Czech koruna';
                         CURARRAY(8)  = 'DKK Danish krone';
                         CURARRAY(9)  = 'GBP Pound sterling';
                         CURARRAY(10) = 'HKD Hong Kong dollar';
                         CURARRAY(11) = 'HRK Croatian kuna';
                         CURARRAY(12) = 'HUF Hungarian forint';
                         CURARRAY(13) = 'IDR Indonesian rupiah';
                         CURARRAY(14) = 'ILS Israeli shekel';
                         CURARRAY(15) = 'INR Indian rupee';
                         CURARRAY(16) = 'ISK Icelandic krona';
                         CURARRAY(17) = 'JPY Japanese yen';
                         CURARRAY(18) = 'KRW South Korean won';
                         CURARRAY(19) = 'LTL Lithuanian litas';
                         CURARRAY(20) = 'LVL Latvian lats';
                         CURARRAY(21) = 'MXN Mexican peso';
                         CURARRAY(22) = 'MYR Malaysian ringgit';
                         CURARRAY(23) = 'NOK Norwegian krone';
                         CURARRAY(24) = 'NZD New Zealand dollar';
                         CURARRAY(25) = 'PHP Philippine peso';
                         CURARRAY(26) = 'PLN Polish zloty';
                         CURARRAY(27) = 'RON New Romanian leu';
                         CURARRAY(28) = 'RUB Russian rouble';
                         CURARRAY(29) = 'SEK Swedish krona';
                         CURARRAY(30) = 'SGD Singapore dollar';
                         CURARRAY(31) = 'THB Thai baht';
                         CURARRAY(32) = 'TRY New Turkish lira';
                         CURARRAY(33) = 'USD US dollar';
                         CURARRAY(34) = 'ZAR South African rand';
                  
                           //Adding the Currencies to a Database
                          For x = 1 To 34;
                            CUR#    = x;
                            CURSYM  = %Subst(CURARRAY(x):1:3);
                            CURNAME = %Subst(CURARRAY(x):5);
                  
                            Write CURLSTREC;
                          ENDFOR;
                  
                         *Inlr = *On;
                         Return;
                  
                        /End-Free

                  Comment


                  • #10
                    Re: Parsing XML with RPGLE.

                    Thanks for being so polite & for posting the finished product so that others may benefit.

                    jamie
                    All my answers were extracted from the "Big Dummy's Guide to the As400"
                    and I take no responsibility for any of them.

                    www.code400.com

                    Comment


                    • #11
                      Re: Parsing XML with RPGLE.

                      Jamie, its my pleasure.

                      Also.
                      I really don't know what the guys at ECB were thinking when they came up with the nested cubes.
                      Seriously! If there was ever someone that needed a good kickinthepants...


                      For or posterity. I removed all the starting junk tags at the start.:
                      Code:
                      
                      
                      	Reference rates
                      	
                      		European Central Bank
                      	 
                      
                      
                      So my final working tag structure for the program is (see below) the same as the DS in the :
                      Code:
                      	
                      		
                      			
                                              ...
                                              ...
                      		
                      		
                      			
                                              ...
                                              ...
                      		
                      	
                      Which corresponds to the DS in my program:
                      Code:
                           D Cube            Ds                  Qualified
                           D  CubeT                              LikeDS(CubeT) Dim(90)                //Prov for 90 Days
                      
                           D  CubeT          Ds                  Qualified Template
                           D   time                        10A
                           D   CubeCur                           LikeDS(CubeCur) Dim(34)              //Prov for 34 Curren
                      
                           D   CubeCur       Ds                  Qualified Template
                           D     currency                   3A
                           D     rate                      10A
                      I hate it when a thread goes on and on and on and on and on and on and on and "Thread Closed"

                      Regards,
                      Christoff

                      Comment

                      Working...
                      X