带有临时表和数据集的示例
此处的数据集仅用于格式化 xml 输出
DEFINE TEMP-TABLE ttCourse NO-UNDO XML-NODE-NAME "Course"
FIELD dSORT AS DECIMAL SERIALIZE-HIDDEN // hidden in xml output
FIELD Name AS CHARACTER
FIELD Credits AS DECIMAL
FIELD NEWFIELD AS CHARACTER
INDEX SORT dSORT ASCENDING. // this index for sorting the xml output Course
DEFINE VARIABLE cxml AS LONGCHAR NO-UNDO.
DEFINE VARIABLE iCnt AS INTEGER NO-UNDO.
// DEFINE DATASET only for xml-node-name
DEFINE DATASET ds
XML-NODE-NAME "Courses" FOR ttCourse.
cxml = "<Courses>
<Course>
<Name>Intro to DB</Name>
<Credits>3.0</Credits>
</Course>
<Course>
<Name>Intro to Programming</Name>
<Credits>3.0</Credits>
</Course>
</Courses>".
TEMP-TABLE ttCourse:READ-XML ("LONGCHAR", cxml, "MERGE", "", FALSE, ?, ?).
// for sorting output use field dsort
FOR EACH ttCourse WHERE ttCourse.DSORT = 0:
iCnt = iCnt + 1.
ttCourse.DSORT = iCnt.
END.
// insert a record in the middle
CREATE ttCourse.
ASSIGN
ttCourse.DSORT = 1.5
ttCourse.name = "test"
ttCourse.credits = 5.5
ttCourse.NEWFIELD = "NEWFIELD"
.
DATASET ds:WRITE-XML ("file", "C:/temp/baz/courses.xml", TRUE,?,?,FALSE,FALSE).