Deal of the Day

Monday, 4 July, 2011

XML Parsing using XML-INTO

Something on XML-INTO

IBM has introduce a new OP-Code XML-INTO, which has make XML parsing as smooth as butter..:)
Steps to use XML-INTO
1.        Define a Data structure or array of data structures that matches the layout of XML document.
2.        Run XML-INTO (This loads the values from XML to Data Structure

Below sample code will help you write simple XML Parsing code.

D qualName        DS                   QUALIFIED
D   FrstName                    10A
D   LastName                    10A

D EmpInfo        DS                   QUALIFIED
D* Employee Name
D   EMPNme                             LIKEDS(qualName)
D* Manager Name
D   MName                              LIKEDS(qualName)

D* Manager Last Name
D MLName          S             10A    VARYING

 //  Assume file Emplpoyee.xml contains the following lines:
 // <EMPNAME><Frstname>Scott</Frstname><LastName>Sherbert</LastName></EMPNAME>
 // <MNANE Frstname="Ken" LastName="Mahajan"></MNAME>

    xml-into empInfo %XML('Employee.xml' : 'doc=file');
 // EMPInfo.EMPNme.Frstname='Scott' EMPInfo.EMPNme.Lastname = 'Sherbert'
 // EMPInfo.MName.Frstname='KenEMPInfo.MName.Lastname = 'Mahajan'

 // Parse the "empinfo/Mname/Lastname" information into variable
 // "MLName".  Use the "path" option to specify the location
 // of this information in the XML document.
  xml-into MLName %XML('Employee.xml'
                   : 'doc=file path=empinfo/MName/lastname';
 // MLName = 'Mahajan'

Do write me @ for any query or you can simply post comments below.

Happy Learning

No comments:

Post a Comment