0
votes

so this should be pretty simple. I'm trying to get data from a XML file in an URL and parsing it into a temp-table so I can use the data in the rest of my program. I've written a code but at the end, DISPLAY PAPEL DESCRICAO. doesn't show anything. Am I doing something wrong? The entire code with the XML link:

DEF TEMP-TABLE CMA NO-UNDO
    FIELD PAPEL       AS CHAR
    FIELD DESCRICAO   AS CHAR
    FIELD ULTIMO      AS  DEC
    FIELD DIFERENCIAL AS  DEC
    FIELD VARIACAO    AS  DEC
    FIELD FECHANT     AS  DEC
    FIELD COMPRA      AS  DEC
    FIELD MINIMA      AS  DEC
    FIELD MAXIMA      AS  DEC
    FIELD VENCIMENTO  AS  INT
    FIELD HORA        AS CHAR
    FIELD DATA        AS DATE.

DEF VAR cSourceType             AS CHAR    NO-UNDO.
DEF VAR cFile                   AS CHAR    NO-UNDO.
DEF VAR cReadMode               AS CHAR    NO-UNDO.
DEF VAR cSchemaLocation         AS CHAR    NO-UNDO.
DEF VAR lOverrideDefaultMapping AS LOGICAL NO-UNDO.
DEF VAR cFieldTypeMapping       AS CHAR    NO-UNDO.
DEF VAR cVerifySchemaMode       AS CHAR    NO-UNDO.
DEF VAR lReturn                 AS LOGICAL NO-UNDO.

ASSIGN
    cSourceType             = "FILE"
    cFile                   = "http://sfeed-cot01.cma.com.br/clientes/cocamar/cbot.xml"
    cReadMode               = "EMPTY"
    cSchemaLocation         = ?
    lOverrideDefaultMapping = ?
    cFieldTypeMapping       = ?
    cVerifySchemaMode       = ?. 

lReturn = TEMP-TABLE CMA:READ-XML(cSourceType, cFile, cReadMode, 
    cSchemaLocation, lOverrideDefaultMapping, cFieldTypeMapping,
    cVerifySchemaMode).
IF lReturn THEN
FOR EACH CMA NO-LOCK:
    DISPLAY CMA.PAPEL CMA.DESCRICAO.
END.

Any help is much appreciated.

1
So, I've been messing around with this and also tried to get XML data with JavaScript and it seems it's an authorization problem... or something. I'll try to get deeper into this and report. - DootyBooty
Sorry, I'm still very much a beginner. - DootyBooty

1 Answers

3
votes

Super close. CMA is not corresponding to the table but to a container tag that could be represented by a Prodataset in this case. Instead just use "QUOTES".

I would not use xml like this in production, you might not have any way to interfere if the source is down etc. I would pull the xml down another way and then load it.

But that's another story...

DEF TEMP-TABLE QUOTES NO-UNDO
    FIELD PAPEL       AS CHAR
    FIELD DESCRICAO   AS CHAR
    FIELD ULTIMO      AS  DEC
    FIELD DIFERENCIAL AS  DEC
    FIELD VARIACAO    AS  DEC
    FIELD FECHANT     AS  DEC
    FIELD COMPRA      AS  DEC
    FIELD MINIMA      AS  DEC
    FIELD MAXIMA      AS  DEC
    FIELD VENCIMENTO  AS  INT
    FIELD HORA        AS CHAR
    FIELD DATA        AS DATE.

DEF VAR cSourceType             AS CHAR    NO-UNDO.
DEF VAR cFile                   AS CHAR    NO-UNDO.
DEF VAR cReadMode               AS CHAR    NO-UNDO.
DEF VAR cSchemaLocation         AS CHAR    NO-UNDO.
DEF VAR lOverrideDefaultMapping AS LOGICAL NO-UNDO.
DEF VAR cFieldTypeMapping       AS CHAR    NO-UNDO.
DEF VAR cVerifySchemaMode       AS CHAR    NO-UNDO.
DEF VAR lReturn                 AS LOGICAL NO-UNDO.

ASSIGN
    cSourceType             = "FILE"
    cFile                   = "http://sfeed-cot01.cma.com.br/clientes/cocamar/cbot.xml"
    cReadMode               = "EMPTY"
    cSchemaLocation         = ?
    lOverrideDefaultMapping = ?
    cFieldTypeMapping       = ?
    cVerifySchemaMode       = ?. 

lReturn = TEMP-TABLE QUOTES:READ-XML(cSourceType, cFile, cReadMode, 
    cSchemaLocation, lOverrideDefaultMapping, cFieldTypeMapping,
    cVerifySchemaMode).

DISP lReturn.
IF lReturn THEN
FOR EACH QUOTES NO-LOCK:
    DISPLAY QUOTES.PAPEL QUOTES.DESCRICAO.
END.