RPGLE XML Parser – XML-SAX as well as XML-INTO sample code Part 4

Click hither to read from laid about Chapter
Before writing the Parsing plan or the XML Cross-Ref generator I would similar to do the re-create origin needed inward both programs together with nosotros don’t accept to set the code 1 time to a greater extent than together with 1 time to a greater extent than inward all programs. It improve to do it this means together with its the best practice.

Member      Type        Text                        
PARSER      RPGLE       Parse XML Data – Routine    
PARSER_H    RPGLE       Parse XML Data – Header    

Header Copy origin for XML Parsing

FQSYSPRT   O    F  132        PRINTER                                                                                                         d PrintMe         ds                  qualified                        d   cite                        21a                                    d   information                       111a                                                                                                            * Date/Time Stamps                                                    d                 ds                                                   d @datetime                       z                                    d  @dtestmp                       d   overlay(@datetime : 1)           d                                     datfmt(*iso)                     d  @timstmp                       t   overlay(@datetime : 12)                                                                                 d mySaxHandler    PR            10i 0                                  d   ignore                       1a                                    d   final result                       10i 0 value                            d   string                        *   value                            d   stringLen                   20i 0 value                            d   exceptionId                 10i 0 value                                                                                                    d myDataHandler   PR            10i 0                      d stackname                  65535a   varying              d                                     value                d stackval                   65535a   varying              d                                     value                                                                           d @date           sec               d                        d @time           sec               t                        d inputFile       sec            500a                        d fileId          sec             20a                        d fileName        sec             50a                        d filePath        sec            250a                        d fieldId         sec           2000a   varying              d xml             sec            500a   varying              d ignoreMe        sec              1a                                                                                   d                sds                                       d  pgmnam           *proc                                  d  prmnbr           *parms                                 d  project                  244    253                         d  userid               254    263      

Routine Copy origin for XML Parsing

P mySaxHandler    B                                             d mySaxHandler    PI            10i 0                           d   ignore                       1a                             d   final result                       10i 0 value                     d   string                        *   value                     d   stringLen                   20i 0 value                     d   exceptionId                 10i 0 value                                                                                     d value           sec          65535a   based(string)             d ucs2val         sec          16383c   based(string)                                                                             d MAX_DEPTH       c                   32                        d depth           sec             10i 0 inz(0) static             d stackname       sec          65535a   varying inz('')           d                                     dim(MAX_DEPTH)            d                                     static                    d stackval        sec          65535a   varying inz('')           d                                     dim(MAX_DEPTH)                     d                                     static                                                                                                       /free                                                                            select;                                                                  when final result = *XML_START_DOCUMENT;                                           depth = 0;                                                               stackname(*) = '';                                                       stackval(*) = '';                                                                                                                              when depth >= MAX_DEPTH                                                     together with ( final result = *XML_START_ELEMENT                                            or final result = *XML_ATTR_NAME );                                           furnish -1;                                                                                                                                    when final result = *XML_START_ELEMENT;                                            depth += 1;                                                              if depth = 1;                                                               stackname(depth) = '/' + %subst(value:1:stringLen);                   else;                                                                       stackname(depth) = stackname(depth-1) + '/'                                               + %subst(value:1:stringLen);                         endif;                                                                   stackval(depth)  = '';                                                                                                             when final result = *XML_ATTR_NAME;                                    depth += 1;                                                  stackname(depth) = stackname(depth-1) + '/@'                                  + %subst(value:1:stringLen);                stackval(depth) = '';                                                                                                  when final result = *XML_END_ELEMENT                                  or final result = *XML_END_ATTR;                                     myDataHandler(stackname(depth):stackval(depth));             depth -= 1;                                                                                                            when final result = *XML_CHARS                                        or final result = *XML_PREDEF_REF                                   or final result = *XML_ATTR_CHARS                                   or final result = *XML_ATTR_PREDEF_REF;                              stackval(depth) += %subst(value:1:stringLen);                                                                          when final result = *XML_UCS2_REF                                     or final result = *XML_ATTR_UCS2_REF;                                stackval(depth) += %char(%subst( ucs2val : 1                                         : %div(stringLen:2) ));           endsl;                                                                               furnish 0;       /end-free              P                 due east                    

Click hither for side past times side Chapter

Recommended Reading

Hosting Unlimited Indonesia


Sumber http://www.mysamplecode.com/