如何将 xml 属性添加到正在进行的临时 table 字段
How to add xml attributes to temp table fields in Progress
DEFINE TEMP-TABLE ttTest
FIELD One AS CHARACTER
FIELD Two AS CHARACTER
FIELD Three AS CHARACTER
.
我想让字段 'Two' 有一个属性 'name',然后有一个值。
所以就这样结束了...
<ttTest>
<One>bla</One>
<Two name="somethingLifeChanging">blabla</Two>
<Three>blablabla</Three>
</ttTest>
有什么想法可以实现吗?
您必须将 temp-table XML 写入 X-DOCUMENT 并在那里操作 XML。
使用数据集你几乎可以达到目的(如果你不关心元素的顺序):
define temp-table ttTest
field parent as recid xml-node-type "hidden"
field One as char
field Three as char
.
define temp-table ttTestTwo serialize-name "Two"
field parent as recid xml-node-type "hidden"
field name as char xml-node-type "attribute"
field Two as char xml-node-type "text"
.
define dataset ds serialize-hidden
for ttTest,ttTestTwo
data-relation for ttTest,ttTestTwo relation-fields( parent, parent ) nested foreign-key-hidden.
create ttTest.
assign
ttTest.parent = recid(tttest)
ttTest.One = "bla"
ttTest.Three = "blablabla"
.
create ttTestTwo.
assign
ttTestTwo.parent = recid( ttTest )
ttTestTwo.name = "something"
ttTestTwo.Two = "blabla"
.
def var lcc as longchar.
dataset ds:handle:write-xml( "longchar", lcc, true ).
message string(lcc ) view-as alert-box.
然后输出是:
---------------------------
Message
---------------------------
<?xml version="1.0"?>
<ttTest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<One>bla</One>
<Three>blablabla</Three>
<Two name="something">blabla</Two>
</ttTest>
---------------------------
OK
---------------------------
DEFINE TEMP-TABLE ttTest
FIELD One AS CHARACTER
FIELD Two AS CHARACTER
FIELD Three AS CHARACTER
.
我想让字段 'Two' 有一个属性 'name',然后有一个值。
所以就这样结束了...
<ttTest>
<One>bla</One>
<Two name="somethingLifeChanging">blabla</Two>
<Three>blablabla</Three>
</ttTest>
有什么想法可以实现吗?
您必须将 temp-table XML 写入 X-DOCUMENT 并在那里操作 XML。
使用数据集你几乎可以达到目的(如果你不关心元素的顺序):
define temp-table ttTest
field parent as recid xml-node-type "hidden"
field One as char
field Three as char
.
define temp-table ttTestTwo serialize-name "Two"
field parent as recid xml-node-type "hidden"
field name as char xml-node-type "attribute"
field Two as char xml-node-type "text"
.
define dataset ds serialize-hidden
for ttTest,ttTestTwo
data-relation for ttTest,ttTestTwo relation-fields( parent, parent ) nested foreign-key-hidden.
create ttTest.
assign
ttTest.parent = recid(tttest)
ttTest.One = "bla"
ttTest.Three = "blablabla"
.
create ttTestTwo.
assign
ttTestTwo.parent = recid( ttTest )
ttTestTwo.name = "something"
ttTestTwo.Two = "blabla"
.
def var lcc as longchar.
dataset ds:handle:write-xml( "longchar", lcc, true ).
message string(lcc ) view-as alert-box.
然后输出是:
---------------------------
Message
---------------------------
<?xml version="1.0"?>
<ttTest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<One>bla</One>
<Three>blablabla</Three>
<Two name="something">blabla</Two>
</ttTest>
---------------------------
OK
---------------------------