Read Write XML

Hello All,

Do anyone has exp. in writing PROGRESS code which reads / write XML?

Can sample code be shared?
Can I pointed in the direction where I could find more Information?

PROGRESS 10
MFGPRO

TIA

Kishor.
 

parul

Member
Since you are on 10.......

it is as simple as:

/*coded directly ..check for syntax errors*/
def temp-table tt1
field tf1 as char
field tf2 as int.

def var a as logical no-undo.

create tt1.
assign tt1.tf1 = 'test'
tt1.tf2 = 2.

a = temp-table tt1:write-xml("file","c:\temp\tt1.xml",true,?,?,false,false).

empty temp-table tt1.

def var b as handle.
b = temp-table tt1:handle.

b:read-xml("file","c:\temp\tt1.xml","empty","",?,?,?).

for each tt1:
disp tt1 with 2 col.
pause.
end.

look for help on read-xml/write-xml for more on parameters.

HTH.

-Parul.
 

tamhas

ProgressTalk.com Sponsor
There are a number of methods available and which you use will depend on the exact version of Progress you have (10 doesn't tell us enough), the specific XML, and what you want to do with it.

The READ-XML and WRITE-XML methods are slam dunk simple, if you have a recent enough version of Progress and the right XML. They work great for exporting from a temp-table to XML and then loading it back into another temp-table, but people who are getting XML from outside sources, over which they have no control, often find that it doesn't map onto a temp-table very well for one reason or another ... wrong sort of nesting or three deep nesting being examples.

If you need to roll your own, there are two options -- DOM and SAX. DOM has been available for a long time so there are more examples floating around, but has the disadvantages that the whole document needs to be parsed and held in memory at one time, which is a problem with large documents, and it is relatively slow, particularly if you are extracting only small parts of the total information. SAX is faster since it parses on the fly and is very easily adapting to picking out only specific information and doesn't use as much memory. Check the manuals for examples (even though they aren't very good ones. There is a SAX reader example in my ABL2UML code at OE Hive.
 
Dear All,

read-xml & write-xml what version of PROGRESS supports it?

I understood PROGRESS read/write with XML in theory.

In practice NODE-VALUE is not returning the value. Pl Help.


Kishor.

/**********************PROGRAM ************************/
/* i-incus.p - Import the Shipment table from an XML file */
DEFINE VARIABLE hDoc AS HANDLE NO-UNDO.
DEFINE VARIABLE hRoot AS HANDLE NO-UNDO.
DEFINE VARIABLE hTable AS HANDLE NO-UNDO.
DEFINE VARIABLE hField AS HANDLE NO-UNDO.
DEFINE VARIABLE hText AS HANDLE NO-UNDO.
DEFINE VARIABLE hBuf AS HANDLE NO-UNDO.
DEFINE VARIABLE hDBFld AS HANDLE NO-UNDO.
DEFINE VARIABLE ix AS INTEGER NO-UNDO.
DEFINE VARIABLE jx AS INTEGER NO-UNDO.
/* So we can create new recs */
DEFINE TEMP-TABLE ttship
FIELDS shipnbr AS c
FIELDS shipdt AS c
FIELDS packtot AS i
FIELDS tracknbr AS i
FIELDS totwt AS DEC.

CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot.
CREATE X-NODEREF hTable.
CREATE X-NODEREF hField.
CREATE X-NODEREF hText.

hBuf = BUFFER ttship:HANDLE.

/* Read in the file created in i-outcus.p */
hDoc:LOAD("file", "d:\879_T3INT98802ES.xml", FALSE).
hDoc:GET-DOCUMENT-ELEMENT(hRoot).

/* Read each Record from the root */
REPEAT ix = 1 TO hRoot:NUM-CHILDREN:
hRoot:GET-CHILD(hTable, ix).
CREATE ttship.
/* Get the fields given as attributes */
shipnbr = hTable:GET-ATTRIBUTE("ShipmentNumber").
shipdt = hTable:GET-ATTRIBUTE("shipdate").
packtot = INT (hTable:GET-ATTRIBUTE("PackingTotal")).
tracknbr = INT (hTable:GET-ATTRIBUTE("TrackingNumber")).
totwt = DEC (hTable:GET-ATTRIBUTE("Totalweight")).


/* Get the remaining fields given as elements with text */

REPEAT jx = 1 TO hTable:NUM-CHILDREN:

MESSAGE "NAME " hTable:NAME " Value " hTable:NODE-VALUE VIEW-AS ALERT-BOX.

hTable:GET-CHILD(hField, jx).
IF hField:NUM-CHILDREN < 1 THEN NEXT.
/* Skip any null value */
hDBFld = hBuf:BUFFER-FIELD(hField:NAME).
hField:GET-CHILD(hText, 1).
/* Get the text value of the field */
hDBFld:BUFFER-VALUE = hTEXT:NODE-VALUE.
END. /* REPEAT jx */
END. /* REPEAT ix */


DELETE OBJECT hDoc.
DELETE OBJECT hRoot.
DELETE OBJECT hTable.
DELETE OBJECT hField.
DELETE OBJECT hText.
/* show data made it by displaying temp-table */
FOR EACH ttship:
DISPLAY ttship.
END.

/************XML **********************/

<?xml version="1.0" encoding="ISO-8859-1" ?>
<shippedorders>
<ShipmentNumber>T3INT98802</ShipmentNumber>
<ShipDate>2007-04-25T16:37:22.530</ShipDate>
<PackingTotal>1</PackingTotal>
<TrackingNumber>123456798</TrackingNumber>
<TrackingLink>http://tracking.ups.com/trackme...</TrackingLink>
<TotalWeight>5.0000</TotalWeight>
</shippedorders>
 
Top