RXS_ParseDomToDom()

This subprocedure retrieves a new RXS_ParseDomDS_t data structure from a parent XML structure, allowing you to retrieve and work with a subset of a larger XML document.

Subprocedure Prototype

CopyrpgleD RXS_ParseDomToDom...
D                 PR                  Extproc('RXS_ParseDomToDom') Opdesc
D                                     Like(RXS_ParseDomDS_t)

Returns an RXS_ParseDomDS_t which contains information and pointers used by subsequent DOM parsing APIs.

CopyrpgleD  pXPath                             Like(RXS_Var8Kv_t) Const
D                                     Options(*Varsize)

XPath used to determine which nodes are retrieved into the RXS_ParseDomDS_t return data structure.

CopyrpgleD  pDS                                LikeDS(RXS_ParseDomDS_t)
D                                     Options(*Varsize)

RXS_ParseDomDS_t data structure, e.g. the “parent” structure.

Example Code

Copyrpgle**FREE
// This example demonstrates starting a DOM parsing session by using
//  RXS_OpenDom and then retrieving a subsection of the DOM structure. This is
//  usually helpful when working with large documents as it can make it easier
//  to specify the correct XPaths to work with the sections of the document
//  that you want to reach. It's important to call RXS_CloseDom once DOM
//  parsing has been completed to free memory used by the DOM parser.

Ctl-Opt ActGrp(*New) BndDir('RXSBND');

/COPY QRPGLECPY,RXSCB

Dcl-Ds RootDomDS LikeDS(RXS_ParseDomDS_t);
Dcl-Ds BookDomDS LikeDS(RXS_ParseDomDS_t);
Dcl-S XPath Like(RXS_Var8Kv_t);
Dcl-S Data Like(RXS_Var1Kv_t);

Dcl-S x Uns(10);

Dcl-S gXML Like(RXS_Var64Kv_t);

gXML = '<?xml version="1.0" encoding="UTF-8"?>'
     + '<bookstore xmlns:test="testnamespace">'
     + '<book category="children">'
     + '<title lang="en"><![CDATA[Charlotte''s Web]]></title>'
     + '<author>E. B. White</author>'
     + '<year>1952</year>'
     + '<price>5.99</price>'
     + '<review><text>What a great book!</text></review>'
     + '<review><text>Highly recommended.</text></review>'
     + '</book>'
     + '<book category="cooking">'
     + '<title lang="en">Everyday Italian</title>'
     + '<author>Giada De Laurentiis</author>'
     + '<year>2005</year>'
     + '<price>30.00</price>'
     + '</book>'
     + '</bookstore>';

RXS_ResetDS( RootDomDS : RXS_DS_TYPE_PARSEDOM );

RootDomDS = RXS_OpenDom( gXML );

XPath = RXS_XPath( '/*:bookstore/*:book' );
RXS_ResetDS( BookDomDS : RXS_DS_TYPE_PARSEDOM );
BookDomDS = RXS_ParseDomToDom( XPath : RootDomDS );

// Any subsequent XPaths used to query BookDomDS no longer
//  need to include the /*:bookstore/ portion of the XPath.
for x = 1 to BookDomDS.NodeCount;
  XPath = RXS_XPath( '*:book[%u]/*:title' : x );
  Data = RXS_ParseDomToText( XPath : BookDomDS );
  RXS_JobLog( 'Title: %s' : Data );
  // This will output:
  // Title: Charlotte's Web
  // Title: Everyday Italian
endfor;

RXS_CloseDom( RootDomDS );

return;

Data Structures

CopyrpgleD RXS_ParseDomDS_t...
D                 DS                  Qualified Template Inz
 
CopyrpgleD   ReturnedErrorInfo...
D                                     LikeDS(RXS_ReturnedErrorInfoDS_t) Inz
 
CopyrpgleD   DataStructureType...
D                                5I 0 Inz(RXS_DS_TYPE_PARSEDOM)

Internal use only

CopyrpgleD   OnErrorMessageType...
D                                5I 0
 
CopyrpgleD   InputCcsid...
D                               10I 0

Specifies the CCSID of the XML being parsed.

CopyrpgleD   OutputCcsid...
D                               10I 0

Specifies the CCSID the parsed data will be converted to.

CopyrpgleD   Stmf...
D                                     Like(RXS_Var1Kv_t)

Specifies an IFS path to an XML file to parse instead of the Input parm.

CopyrpgleD   NodeCount                   10U 0

Contains the current count of XML nodes tracked by this data structure.

CopyrpgleD   NodeType                    10I 0
 
CopyrpgleD   xmlPtr                        *

Internal use only

CopyrpgleD   docPtr                        *

Internal use only

CopyrpgleD   contextPtr                    *

Internal use only

CopyrpgleD   dictPtr                       *

Internal use only

CopyrpgleD   currentPtr                    *

Internal use only

CopyrpgleD   parentPtr                     *

Internal use only

CopyrpgleD   Reserved                  4096A

Internal use only