using READ-XML to read XML into temp table.

bino

Member
Hi,

I've been testing the new READ-XML method features in Progress 10.1A that allows one to read an XML file into a temp-table versus using the sax parse method.

Basically I just setup a simple procedure based of information from the Progress knowledge base. Created a preset xml, run my procedure to read the xml file and simply output values doing a for each on the temp table. Obviously Im missing something because the temp table doesnt seem to get populated. Any help appreciated. You can try testing my proc by putting it and the xml file in the same directory and run it from the command line.

This is posted in webspeed area because I will eventually be parsing an xml file received via a returned POST using WEB-CONTEXT:X-DOCUMENT. Also, maybe this all can be helpful for the dozens of other folks trying to get better info on utilizing these features. These same features would be used if you were to populate a prodataset.

Code below:

Code:
def temp-table tt-item
   field item-number          as char
   field upc                  as char
   field username             as char
   field password             as char.
 
def var v-return-mode        as log  no-undo.
def var v-sourcetype         as char no-undo.
def var v-read-xml           as char no-undo.
def var v-read-xml-path      as char no-undo.
def var v-readmode           as char no-undo.
def var v-schemapath         as char no-undo.
def var v-override-def-map   as log  no-undo.
def var v-field-type-map     as char no-undo.
def var v-verify-schema-mode as char no-undo.
def var v-test_xml           as char no-undo.
 
/* assign values for read type definitions */
assign v-sourcetype         = "FILE"
       v-read-xml           = "myitem.xml"
       v-read-xml-path      = "xml/" + v-read-xml
       v-readmode           = "EMPTY"
       v-schemapath         = ?
       v-override-def-map   = ?
       v-field-type-map     = ? 
       v-verify-schema-mode = ?.
 
/********************************************************************/
/* we read in the xml file and create our temp table. We assign our */
/* v-return-mode true or false if any records are read from the xml */
/********************************************************************/
v-return-mode = 
TEMP-TABLE tt-item:READ-XML(v-sourcetype, v-read-xml-path , v-readmode, 
                            v-schemapath, v-override-def-map, 
                            v-field-type-map, v-verify-schema-mode).
 
 
/* Now we read through our temp table records */
if v-return-mode then
do:
   for each tt-item:
   display tt-item.item-number.
   end.
end.
else
display "failed". /* test output */
return.


And a very simple example of the xml file being loaded
<?xml version="1.0" encoding="ISO-8859-1"?>
<CATALOG>
<ITEM>
<USERNAME>test</USERNAME>
<PASSWORD>test1</PASSWORD>
<ITEMNO>BB55667Y</ITEMNO>
</ITEM>
<ITEM>
<USERNAME>test</USERNAME>
<PASSWORD>test2</PASSWORD>
<ITEMNO>CC55667Y</ITEMNO>
</ITEM>
<ITEM>
<USERNAME>test</USERNAME>
<PASSWORD>test3</PASSWORD>
<ITEMNO>DD55667Y</ITEMNO>
</ITEM>
</CATALOG>
 

Casper

ProgressTalk.com Moderator
Staff member
Hi there,

You're verify schema mode defaults to LOOSE, which means for temptables that (from help):
Matches temp-table columns by name. The data type and extent of the column in the XML Schema must match those for the matching column in the temp-table. Other field attributes in the XML Schema are ignored.

Since in the temp-table you're field is called item-number and in the XML document the field is named itemno, this field is ignored. If you rename you're temp-table field to itemno then it will get filled.

HTH,

Casper.
 

bino

Member
Geez that worked. Thanks Casper I appreciate it. Are there any pros and cons to using this method versus using the sax method? This seems so much easier than using the sax parser, but if the XML has nested levels of nodes etc is the sax method better?
 

Cecil

19+ years progress programming and still learning.
I to have been playing around with importing XML into Temp-Tables and ProDataSets. But I have come across a few problems.
  • It seams to me that the Root Node of the the XML has to be the same name as the Temp-Table. I am trying to import a 3rd party XML where the root node would go against my coding standards. Example: <vcContact></vcContact> would become DEFINE TEMP-TABLE vcContact ....
  • Mapping elements to field names can be a bit of a bugger for example when the element name is <TITLE>. Title is a progress reserve word so you cannot do: DEFINE TEMP-TABLE tt-XML NO-UNDO FIELD TITLE AS CHARACTER.
  • Not all XML use XSD file.
 
Top