如何导出正在进行的 XML?

问题描述

我是 OpenEdge 的新手,我试图将最初的两个表导出到 XML 文件。我的最终目标是将 XML 文件导出为:

<?xml version="1.0" encoding="utf-8"?>
<LAS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <LASRow>
  <temp_wonbr>wo01</temp_wonbr>
  <temp_id>01</temp_id>
  <Allocations>
    <AllocDetail>
        <Emplacement>SUP.TR</Emplacement>
        <Reference/>
        <NumLot>22045</NumLot>
        <Expire/>
        <Qalloc>1</Qalloc>
        <Message/>
    </AllocDetail>
    <AllocDetail>
        <Emplacement>SUP.TR</Emplacement>
        <Reference/>
        <NumLot>22046</NumLot>
        <Expire/>
        <Qalloc>1</Qalloc>
        <Message/>
    </AllocDetail>
    <Allocations>
</LASRow>

[在此处输入图片说明][1]

感谢您的帮助! [1]:https://i.stack.imgur.com/0yWOP.png

解决方法

您可以通过将临时表与数据集中的关系结合起来并在数据集上使用 write-xml 方法来实现您想要的:

define temp-table ttlas no-undo
  field temp_wonbr as char
  field temp_id as char
  .

define temp-table ttallocations no-undo
  field parent_id as recid serialize-hidden
  .

define temp-table ttallocdetails no-undo
  field parent_id       as recid serialize-hidden

  field Emplacement as char
  field Reference   as char
  field NumLot      as int 
  field lexpire     as char serialize-name 'Expire'
  field Qalloc      as int 
  field cmessage    as char serialize-name 'Message'
  .

define buffer bulas for ttlas serialize-name 'LASRow'.
define buffer buallocation for ttallocations serialize-name 'Allocations'.
define buffer budetail for ttallocdetails serialize-name 'AllocDetail'.

define dataset dslas serialize-name 'LAS'
  for bulas,buallocation,budetail
  parent-id-relation for bulas,buallocation parent-id-field parent_id
  parent-id-relation for buallocation,budetail parent-id-field parent_id
  .

create bulas.
assign
  bulas.temp_wonbr = 'wo01'
  bulas.temp_id = '01'
  .

create buallocation.
assign
  buallocation.parent_id = recid( bulas )
  .

create budetail.
assign 
  budetail.parent_id = recid( buallocation )
  budetail.emplacement = 'SUP.TR'
  budetail.numlot = 22045
  budetail.qalloc = 1
  .

create budetail.
assign 
  budetail.parent_id = recid( buallocation )
  budetail.emplacement = 'SUP.TR'
  budetail.numlot = 22046
  budetail.qalloc = 1
  .


def var lcxml as longchar no-undo.
dataset dslas:write-xml( 'longchar',lcxml,true,?,true ).

message string( lcxml ).

https://abldojo.services.progress.com/?shareId=603f5bda9585066c2197989a

,

使用数据集,您几乎可以导出任何 XML(有一些限制,例如无法创建 xml 注释)。

您可能不得不摆弄用字符替换某些数据类型以正确创建空标签(空的或真正包含 ? 的日期将创建另一个您可能不想要的结构)。

这会让你开始

DEFINE TEMP-TABLE ttLASRow NO-UNDO SERIALIZE-NAME "LASRow"
    FIELD temp_wonbr AS CHARACTER 
    FIELD temp_id    AS CHARACTER.

DEFINE TEMP-TABLE ttAllocations NO-UNDO SERIALIZE-NAME "Allocations"    
    FIELD parentid AS RECID SERIALIZE-HIDDEN. 
    
DEFINE TEMP-TABLE ttAllocDetails NO-UNDO SERIALIZE-NAME "AllocDetails"  
    FIELD parentId    AS RECID SERIALIZE-HIDDEN 
    FIELD Emplacement AS CHARACTER
    FIELD Reference   AS CHARACTER 
    FIELD NumLot      AS INTEGER
    FIELD ExpDat      AS CHARACTER SERIALIZE-NAME "Expire"
    FIELD Qalloc      AS INTEGER 
    FIELD msg         AS CHARACTER SERIALIZE-NAME "Message".

DEFINE DATASET dsLAS SERIALIZE-NAME "LAS" FOR ttLasRow,ttAllocations,ttAllocDetails
    PARENT-ID-RELATION FOR ttLasRow,ttAllocations PARENT-ID-FIELD parentId
    PARENT-ID-RELATION FOR ttAllocations,ttAllocDetails PARENT-ID-FIELD parentId
    .

CREATE ttLasRow.
ASSIGN ttLasRow.temp_wonbr = "wo01"
       ttLasRow.temp_id    = "01".
       
CREATE ttALlocations.      
ASSIGN ttAllocations.parentId = RECID(ttLasRow).

CREATE ttAllocDetails.
ASSIGN ttAllocDetails.parentid    = RECID(ttAllocations)
       ttAllocDetails.Emplacement = "SUP.TR"
       ttAllocDetails.NumLot      = 22045
       ttAllocDetails.Qalloc      = 1.

CREATE ttAllocDetails.
ASSIGN ttAllocDetails.parentid    = RECID(ttAllocations)
       ttAllocDetails.Emplacement = "SUP.TR"
       ttAllocDetails.NumLot      = 22046
       ttAllocDetails.Qalloc      = 1.      
       
       
DATASET dsLAS:WRITE-XML("file","c:\temp\xml.xml").   
,
TEMP-TABLE ttTempTableName:WRITE-XML ("FILE","c:\temp\filename.xml",TRUE,?).