Skip to main content  
        iSeries home   |   Easy400  
Public-Source
 
Introduction
 
More commands ...
 RNMXMLFLDS
CRTTODBF
SUPERPARSE
 
 Download
 
 

 
ez4Parse
Public Source XML Parser
RNMXMLFLDS - Rename XML Fields

Let us have another look at our sample XML script, /ez4parse/examples/boooks.xml:

<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications 
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
   </book>
</catalog>
Figure 1 - Sample XML stream file

As we want to use command XMLPARSE to upload the XML data to an IBM i database file of ours, we need to rename the XML fields to match the field names of our database file:

XML field namedatabase field name
IDID
AUTHORBKAUTHOR
TITLEBKTITLE
GENREBKGENRE
PRICEBKPRICE
PUBLISH_DATEBKPUBDATE
DESCRIPTIONBKDESCR

This can be easily done with command RNMXMLFLDS (Rename XML Fields).
This command creates a slightly modified XML stream file, where the XML field names are replaced with your desired ones.

The following example shows how it works.

                              Rename XML fields (RNMXMLFLDS)

 Type choices, press Enter.

 Input XML stream file  . . . . . STMFIN      '/ez4parse/examples/books.xml'              
                                                                                          
 Output XML stream file . . . . . STMFOUT     '/tmp/mybooks.xml'                          
                                                                                          
 Path to the XML elements . . . . XMLPTH      *AUTO                                       
                                                              
 Number of segments in XMLPTH . . XMLPTHNBR   2             1-99                          
 Display output stream file . . . DSPSTMFOUT  *yes          *YES, *NO


Figure 2 - Command RNMXMLFKLDS
Try it:   RNMXMLFLDS STMFIN('/ez4parse/examples/books.xml')
STMFOUT('/tmp/mybooks.xml')
  • Input XML stream file (STMFIN):
    Path and name of the XML stream file with data element ("field") names to be changed.
    Restriction: the size of this file cannot exceed 15 Mb.
  • Output XML stream file (STMFOUT):
    Path and name of the stream file that will contain the new version of the input XML stream file.
    This output stream file does not have to exist. If existing, it is deleted, and is created from this command.
  • Path to the XML elements (XMLPTH):
    See the explanations given for this same parameter in command XMLPARSE.
    If a path (instead of *AUTO) is specified, some attention should be payed, as the path (example: Roset/Row) is case sensitive and must perfectly match the corresponding HTML tags.
  • Number of segments in XMLPTH (XMLPTHNBR):
    See the explanations given for this same parameter in command XMLPARSE.
  • Display output stream file (DSPSTMFOUT):
    Whether the output stream file should be displayed after having been generated.

After pressing the Enter key you receive the following screen:

                        RNMXMLFLDS - Rename XML Fields                          
                                                                                
 Input  stmf . . . /ez4parse/examples/books.xml                                 
 Output stmf . . . /tmp/mybooks.xml                                             
                                                                                
 Type new field names and press F13 to rename fields in the output stream file. 
                                                                                
 Current XML field name                              Key  New XML field name    
 id                                                   K   id        
 author                                                   author                
 title                                                    title                 
 genre                                                    genre                 
 price                                                    price                 
 publish_date                                             publish_da            
 description                                              descriptio            
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                         Bottom 
 F3=End  F12=Previous  F13=Confirm rename
                                      
Figure 3 - Command RNMXMLFKLDS, before typing the new XML field names

Note that

  1. The suggested new XML field names have been cut to 10 characters.
  2. The field name id (captured from the XML tag <book id="bk101">) has been detected as a key field for the target database file.

Type the new XML field names:

                        RNMXMLFLDS - Rename XML Fields                          
                                                                                
 Input  stmf . . . /ez4parse/examples/books.xml                                 
 Output stmf . . . /tmp/mybooks.xml                                             
                                                                                
 Type new field names and press F13 to rename fields in the output stream file. 
                                                                                
 Current XML field name                              Key  New XML field name    
 id                                                   K   bkid                 
 author                                                   bkauthor              
 title                                                    bktitle               
 genre                                                    bkgenre               
 price                                                    bkprice               
 publish_date                                             bkpubdate             
 description                                              bkdescr               
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                         Bottom 
 F3=End  F12=Previous  F13=Confirm rename
                                      
Figure 4 - Command RNMXMLFKLDS, after typing the new XML field names

then press F13.
The new stream file /tmp/mybooks.xml (Specified in parameter STMFOUT of command RNMXMLFLDS) is generated and it looks as follow:

<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <bkauthor>Gambardella, Matthew</bkauthor>
      <bktitle>XML Developer's Guide</bktitle>
      <bkgenre>Computer</bkgenre>
      <price>44.95</price>
      <bkpubdate>2000-10-01</bkpubdate>
      <bkdescr>An in-depth look at creating applications 
      with XML.</bkdescr>
   </book>
   <book id="bk102">
      <bkauthor>Ralls, Kim</bkauthor>
      <bktitle>Midnight Rain</bktitle>
      <bkgenre>Fantasy</bkgenre>
      <bkprice>5.95</bkprice>
      <bkpubdate>2000-12-16</bkpubdate>
      <bkdescr>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</bkdescr>
   </book>
</catalog>
Figure 5 - The new XML stream file with different XML field names
  • If you have a database file (in the example: file BOOKS in library QGPL) with record format fields matching those of this new XML stream file, then you can now run command XMLPARSE to upload the XML data:
                           Parse a XML stream file (XMLPARSE)
     
     Type choices, press Enter.
    
     XML stream file  . . . . . . . . STMF       > /tmp/mybooks.xml                            
                                                                                    
     Path to the XML elements . . . . XMLPTH       *AUTO                                       
                                                                                               
                                                                                               
                                                                                               
     Number of segments in XMLPTH . . XMLPTHNBR    2             1-99
     Target database file . . . . . . TOFILE       BOOKS         Name
       library  . . . . . . . . . . .                QGPL        Name, *LIBL, *CURLIB
     Target member  . . . . . . . . . TOMBR        *FILE         Name, *FILE
     Replace or add records . . . . . MBROPT       *REPLACE      *ADD, *REPLACE
     Take default parsing options . . DFTOPTIONS > *NO           *YES, *NO
      1.CCSID parsing option  . . . . CCSID        *BEST         *BEST, *JOB, *UCS2
      2.TRIM parsing option . . . . . TRIM         *ALL          *ALL, *NONE
      3.ALLOWMISSING parsing option   ALWMISSING   *YES          *YES, *NO
      4.ALLOWEXTRA parsing option . . ALWEXTRA     *YES          *YES, *NO
                                                                                        Bottom
    Command XMLPARSE

  • If you have no database file with record format fields matching those of this new XML script, then you can take advantage from command CRTTODBF (Create the "TO" Database File) to create it from such a XML script.
    See the next page.

Special note

The utility maintains some memory, for some time, of the renaming performed on XML data elements ("XML fields") names. Therefore it should be no wonder if it - in Figure 3 - returns the renamed field names the user entered the last time the same XML stream file was processed.