本文介绍了在Progress-4gl中将XML文件读取到数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 XML文件就是这样

<A_VERY_VERY_LONG_TITLE xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/">
    <DATA_LIST>
        <DATA_LIST>         
            <ELEMENT_NO1 xmlns="">ABCDEFG_1</ELEMENT_NO1>
            <ELEMENT_NO2 xmlns="">1234567_1</ELEMENT_NO2>
            <ELEMENT_NO3 xmlns=""/>         
        </DATA_LIST>
        <DATA_LIST>
            <ELEMENT_NO1 xmlns="">ABCDEFG_2</ELEMENT_NO1>
            <ELEMENT_NO2 xmlns="">1234567_2</ELEMENT_NO2>
            <ELEMENT_NO3 xmlns="">A1B2C3D_2</ELEMENT_NO3>       
        </DATA_LIST>
        <DATA_LIST>
            <ELEMENT_NO1 xmlns="">ABCDEFG_3</ELEMENT_NO1>
            <ELEMENT_NO2 xmlns="">1234567_3</ELEMENT_NO2>
            <ELEMENT_NO3 xmlns="">A1B2C3D_3</ELEMENT_NO3>       
        </DATA_LIST>
    </DATA_LIST>
    <SOMETHING>SOME-VALUE</SOMETHING>
    <SOMETHING_ELSE>SOME-OTHER-VALUE</SOMETHING_ELSE>
</A_VERY_VERY_LONG_TITLE>

我的代码示例

DEFINE VARIABLE lOK      AS LOGICAL NO-UNDO.

DEFINE TEMP-TABLE DATA_LIST NO-UNDO
    FIELD ELEMENT_NO1           AS CHARACTER
    FIELD ELEMENT_NO2           AS CHARACTER
    FIELD ELEMENT_NO3           AS CHARACTER   .

DEFINE DATASET DATA FOR DATA_LIST.

lOk = DATASET DATA:READ-XML("file",                /* SourceType             */
                            "C:\xmlFile.xml",      /* File                   */
                            "append",              /* ReadMode               */
                            ?,                     /* SchemaLocation         */
                            ?,                     /* OverrideDefaultMapping */
                            ?,                     /* FieldTypeMapping       */
                            ?).                    /* VerifySchemaMode       */

FOR EACH DATA_LIST:
    DISPLAY DATA_LIST.ELEMENT_NO1   FORMAT "x(20)"
            DATA_LIST.ELEMENT_NO2   FORMAT "x(20)"
            DATA_LIST.ELEMENT_NO3   FORMAT "x(20)"
    WITH WIDTH 120  .

END.

我可以成功访问DATA_LIST元素.但是我无法访问"SOMETHING" "SOMETHING_ELSE" 的数据.我也尝试为此值定义一个临时表,但它无法正常工作. (我的屏幕空了.)

I can access DATA_LIST elements succesfully. But I can't reach data "SOMETHING" and "SOMETHING_ELSE" . I've tried to Define a Temp-Table for this values too but it couldn't work. (I'm getting an empty screen.)

感谢您的帮助.

推荐答案

某些东西在Data_List表的定义之外.试试这个:

The something and something else are outside the definition of the Data_List table. Try this:

DEFINE VARIABLE lOK      AS LOGICAL NO-UNDO.

DEFINE TEMP-TABLE DATA_LIST NO-UNDO
    FIELD ELEMENT_NO1           AS CHARACTER
    FIELD ELEMENT_NO2           AS CHARACTER
    FIELD ELEMENT_NO3           AS CHARACTER   .

Define Temp-Table A_VERY_VERY_LONG_TITLE no-undo
    field SOMETHING as character
    field SOMETHING_ELSE as character.

DEFINE DATASET DATA FOR DATA_LIST, A_VERY_VERY_LONG_TITLE.

lOk = DATASET DATA:READ-XML("file",                /* SourceType             */
                            "C:\xmlFile.xml",      /* File                   */
                            "append",              /* ReadMode               */
                            ?,                     /* SchemaLocation         */
                            ?,                     /* OverrideDefaultMapping */
                            ?,                     /* FieldTypeMapping       */
                            ?).                    /* VerifySchemaMode       */

FOR EACH DATA_LIST:
    DISPLAY DATA_LIST.ELEMENT_NO1   FORMAT "x(20)"
            DATA_LIST.ELEMENT_NO2   FORMAT "x(20)"
            DATA_LIST.ELEMENT_NO3   FORMAT "x(20)"
    WITH WIDTH 120  .
END.
For EACH A_VERY_VERY_LONG_TITLE:
    DISPLAY A_VERY_VERY_LONG_TITLE.SOMETHING format "x(40)"
            A_VERY_VERY_LONG_TITLE.SOMETHING_ELSE format "x(40)" 
    WITH WIDTH 220.
END.

对我有用:)

这篇关于在Progress-4gl中将XML文件读取到数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 14:06