我正在访问soap webservice的方法,它正在回复我以下结果。
<ExportTableDataResponse xmlns="http://sisteplant.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ExportTableDataResult>
<root xmlns="">
<table name="Search">
<r>
<c name="c0">1</c>
<c name="c2">05/09/2014 10:23:00</c>
<c name="c3">05/09/2014 00:00:00</c>
<c name="c5">PRE</c>
<c name="c6">0</c>
<c name="c7">1</c>
<c name="c8">0</c>
<c name="c9">m0000p</c>
<c name="c10">ALM06</c>
<c name="c11">A1</c>
<c name="c12">1,0000</c>
<c name="c13">1000,00000</c>
<c name="c14">PRE</c>
<c name="c15">1</c>
<c name="c17">0</c>
</r>
</table>
</root>
</ExportTableDataResult>
我尝试使用以下代码转换数据集的xml但不起作用。我使用版本10.2b的进度
DEFINE TEMP-TABLE MessageTypeCode NO-UNDO XML-NODE-NAME 'r'
FIELD NAME AS CHARACTER XML-NODE-TYPE "Attribute"
FIELD ElementValue AS CHARACTER XML-NODE-TYPE "Text"
FIELD c_recid AS RECID XML-NODE-TYPE "Hidden".
DEFINE DATASET ReceiverInfo XML-NODE-NAME 'table'
FOR MessageTypeCode.
DATASET ReceiverInfo:READ-XML("file", "c:\temp\resultado-pesquisa.xml", "empty", ?, FALSE, ?, "IGNORE") NO-ERROR.
FOR EACH MessageTypeCode:
DISP MessageTypeCode.ElementValue FORMAT "X(30)"
MessageTypeCode.NAME
MessageTypeCode.c_recid.
PAUSE.
END.
然后有人有一些sujestion如何将这个xml转换为数据集?
感谢您的帮助!
答案 0 :(得分:2)
您需要定义所有&#34;等级&#34;数据集作为单独的TEMP-TABLE,您还需要在数据集中将它们的关系定义为&#34; NESTED&#34;。
DEFINE TEMP-TABLE ttExportTableDataResult NO-UNDO XML-NODE-NAME "ExportTableDataResult"
FIELD c_recid AS RECID XML-NODE-TYPE "Hidden".
DEFINE TEMP-TABLE ttRoot NO-UNDO XML-NODE-NAME "root"
FIELD c_recid AS RECID XML-NODE-TYPE "Hidden"
FIELD xmlns AS CHARACTER XML-NODE-TYPE "Attribute".
DEFINE TEMP-TABLE ttTable NO-UNDO XML-NODE-NAME "table"
FIELD tablename AS CHARACTER XML-NODE-TYPE "Attribute" XML-NODE-NAME "name"
FIELD c_recid AS RECID XML-NODE-TYPE "Hidden".
DEFINE TEMP-TABLE ttR NO-UNDO XML-NODE-NAME 'r'
FIELD c_recid AS RECID XML-NODE-TYPE "Hidden".
DEFINE TEMP-TABLE ttMessageTypeCode NO-UNDO XML-NODE-NAME 'c'
FIELD cName AS CHARACTER XML-NODE-TYPE "Attribute" XML-NODE-NAME "name"
FIELD ElementValue AS CHARACTER XML-NODE-TYPE "Text"
FIELD c_recid AS RECID XML-NODE-TYPE "Hidden".
DEFINE DATASET dsReceiverInfo XML-NODE-NAME 'ExportTableDataResponse'
FOR ttExportTableDataResult, ttRoot, ttTable, ttR, ttMessageTypeCode
DATA-RELATION dr1 FOR ttExportTableDataResult, ttRoot RELATION-FIELDS(c_recid, c_recid) NESTED
DATA-RELATION dr2 FOR ttRoot, ttTable RELATION-FIELDS(c_recid, c_recid) NESTED
DATA-RELATION dr3 FOR ttTable, ttR RELATION-FIELDS(c_recid, c_recid) NESTED
DATA-RELATION dr4 FOR ttR, ttMessageTypeCode RELATION-FIELDS(c_recid, c_recid) NESTED
.
/* Removing NO-ERROR - so it will crash instead if there's an error! */
DATASET dsReceiverInfo:READ-XML("file", "c:\temp\dataset.xml", "empty", ?, FALSE, ?, "ignore") .
FOR EACH ttMessageTypeCode:
DISP ttMessageTypeCode.ElementValue FORMAT "X(30)"
ttMessageTypeCode.cName
ttMessageTypeCode.c_recid.
END.
/* Saving the dataset for comparison (you will see that some root-level data is missing) */
DATASET dsReceiverInfo:WRITE-XML("file", "c:\temp\dataset_new.xml") .
答案 1 :(得分:0)
Progress希望read-xml()的XML看起来像这样:
<?xml version="1.0"?>
<tt_sample xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<tt_sampleRow>
<f1>1</f1>
<f2>abc</f2>
</tt_sampleRow>
</tt_sample>
创建read-xml()的XML的示例程序:
define temp-table tt_sample
field f1 as integer
field f2 as character
.
create tt_sample.
assign
f1 = 1
f2 = "abc"
.
buffer tt_sample:write-xml( "file", "sample.xml" ).
答案 2 :(得分:0)
使用正确建模的数据集,您可以:
define temp-table tttable serialize-name "table"
field itable as int xml-node-type "hidden"
field name as char xml-node-type "attribute"
.
define temp-table ttr serialize-name "r"
field itable as int
field irow as int xml-node-type "hidden"
.
define temp-table ttc serialize-name "c"
field itable as int xml-node-type "hidden"
field irow as int xml-node-type "hidden"
field name as char xml-node-type "attribute"
field cvalue as char xml-node-type "text"
.
define dataset ds serialize-name "ExportTableDataResponse"
for tttable, ttr, ttc
data-relation for tttable, ttr relation-fields ( itable, itable ) nested foreign-key-hidden
data-relation for ttr, ttc relation-fields ( itable, itable, irow, irow ) nested foreign-key-hidden
.
create tttable. assign tttable.itable = 0 tttable.name = "Search".
create ttr. assign ttr.irow = 0.
create ttc. assign ttc.name = "c0" ttc.cvalue = "1".
create ttc. assign ttc.name = "c1" ttc.cvalue = "05".
def var lcc as longchar.
dataset ds:write-xml( "longchar", lcc, true ).
message string(lcc) view-as alert-box.
输出:
---------------------------
Message
---------------------------
<?xml version="1.0"?>
<ExportTableDataResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<table name="Search">
<r>
<c name="c0">1</c>
<c name="c1">05</c>
</r>
</table>
</ExportTableDataResponse>
---------------------------
OK
---------------------------