Question

I need to read XML file from an URL. I have no problems if the file is physically present. Then i parse it using the SAX reader.

Now i need to read a XML file from an URL - twice.

First time in need to get it from http://someurl/paging$1,1 , then extract value from total-items in the head of the document.

After that I need to get the XML from the same url , only with last 1 replaced with value from total-items . This way i get all the items that are available for me.

Now I'm stumped already at the beginning. How do I make progress to read XML from URL ? I see there is an option with READ-XML(), but that one stores it in temp-tables.

Using Progress Openedge ver. 11

Was it helpful?

Solution

For "raw" xml support you can use the X-DOCUMENT handle.

DEFINE VARIABLE hXDoc AS HANDLE      NO-UNDO.
CREATE X-DOCUMENT hXDoc.
hXDoc:LOAD("file","http://someurl/paging$1,1", TRUE).
/* Here you need to parse */
DELETE OBJECT hXDoc.

Depending on the structure of the xml-document you can use READ-XML with a temp-table or a dataset to load data directly into it. But then you would need to define the dataset before. This genereally don't work well with dynamically created items.

Check out the documentation around xml here

If all things fails you could wrap a os utility like curl or wget (as regards to Tims answer). A simple wrapper around wget could look like this (curl would be similar):

DEFINE INPUT  PARAMETER pcUrl     AS CHARACTER   NO-UNDO.
DEFINE INPUT  PARAMETER pcPrefix  AS CHARACTER   NO-UNDO.
DEFINE OUTPUT PARAMETER pcFile    AS CHARACTER   NO-UNDO.

pcFile = "wget." + pcPrefix + "." + STRING(TODAY,"999999") + REPLACE(STRING(TIME,"HH:MM:SS"),":","") + "-" + STRING(RANDOM(0,1000),"9999"). 

OS-COMMAND SILENT VALUE("wget '" + pcUrl + "' -o /dev/null -O /tmp/" + pcFile).

OTHER TIPS

READ-XML requires the XML data to be in a storage area such as a LONGCHAR, MEMPTR, FILE, or handle.

In order to use this function with your application, you'll need to d/l the xml payload to one of those storage areas, and then read it in.

One possibility would be to create a SOCKET, use the socket to do a "get" call for the http request, read the response to a MEMPTR, then READ-XML the data into your TT.

Another option would be to use "curl" (http://curl.haxx.se/) to get the XML data to a READ-XML storage area, and then parse the XML file that way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top