我正在OpenEdge 11.1中开发,可以从静态数据成功创建XML文档,并通过SOAP连接到第三方API。
我想将现有的XML对象添加到我正在创建的新文档中,根据Progress Help我应该能够添加类型为“DOCUMENT-FRAGMENT”的节点。当我这样做时,我的父节点只是空的,我没有收到任何错误消息。
是否有某种特定的方法将对象分配给新节点?我正在尝试使用一些静态数据(一串有效的XML),甚至考虑编码字符串以防它无法处理格式。
有没有人在此之前实现这一目标,我做错了什么?
DEFINE VARIABLE hDoc AS HANDLE NO-UNDO.
DEFINE VARIABLE hRoot AS HANDLE NO-UNDO.
DEFINE VARIABLE hNode AS HANDLE NO-UNDO.
DEFINE VARIABLE hRow AS HANDLE NO-UNDO.
DEFINE VARIABLE clData AS LONGCHAR NO-UNDO.
CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot.
CREATE X-NODEREF hNode.
CREATE X-NODEREF hRow.
hDoc:CREATE-NODE(hRoot,"NewDocument","ELEMENT").
hDoc:APPEND-CHILD(hRoot).
hRoot:SET-ATTRIBUTE("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance").
/* NewDocument Product data */
hDoc:CREATE-NODE(hNode,"Product","ELEMENT").
hRoot:APPEND-CHILD(hNode).
/* Product Detail */
hDoc:CREATE-NODE(hRow,"","DOCUMENT-FRAGMENT").
hNode:APPEND-CHILD(hRow).
hRow:NODE-VALUE = '<Available>10</Available><ProductCode>ABC</ProductCode>~
<ProductName>Special</ProductName><ValidFrom>2014-05-02T08:15:00</ValidFrom>~
<ValidTo>2014-05-02T12:45:00</ValidTo><Comments xsi:nil="true" />~
<Price>9.00</Price><PriceID>123456789</PriceID>'.
hDoc:SAVE("LONGCHAR", clData).
DELETE OBJECT hDoc.
DELETE OBJECT hRoot.
DELETE OBJECT hRow.
DELETE OBJECT hNode.
OUTPUT TO "test.log" APPEND.
PUT UNFORMATTED "Start request... " SKIP.
OUTPUT CLOSE.
COPY-LOB clData TO FILE "test.log" APPEND.
答案 0 :(得分:0)
文档片段看起来很有趣 - 但似乎毫无用处。
在解决方法角落,您可以将产品详细信息导入新的x文档,然后使用import-node将数据复制到目标文档。
DEFINE VARIABLE hDoc AS HANDLE NO-UNDO.
DEFINE VARIABLE hRoot AS HANDLE NO-UNDO.
DEFINE VARIABLE hNode AS HANDLE NO-UNDO.
DEFINE VARIABLE hRow AS HANDLE NO-UNDO.
DEFINE VARIABLE lcc AS LONGCHAR NO-UNDO.
CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot.
hDoc:CREATE-NODE( hRoot, "Root", "ELEMENT" ).
hDoc:APPEND-CHILD( hRoot ).
/* NewDocument Product data */
CREATE X-NODEREF hNode.
hDoc:CREATE-NODE( hNode, "Product", "ELEMENT" ).
DEFINE VARIABLE hdocfrag AS HANDLE NO-UNDO.
/* Product Detail */
lcc = '<Available>10</Available><ProductCode>ABC</ProductCode><ProductName>Special</ProductName><ValidFrom>2014-05-02T08:15:00</ValidFrom><ValidTo>2014-05-02T12:45:00</ValidTo><Comments xsi:nil="true" /><Price>9.00</Price><PriceID>123456789</PriceID>'.
lcc = SUBSTITUTE( '<Product>&1</Product>', lcc ).
CREATE X-DOCUMENT hdocfrag.
hdocfrag:LOAD( "longchar", lcc, FALSE ) NO-ERROR. /* no-error to suppress xsi 'warning' */
CREATE X-NODEREF hrow.
hdocfrag:GET-DOCUMENT-ELEMENT( hrow ).
hdoc:IMPORT-NODE( hnode, hrow, TRUE ).
DELETE OBJECT hrow.
DELETE OBJECT hdocfrag.
hRoot:APPEND-CHILD( hNode ).
hDoc:SAVE( "LONGCHAR", lcc ).
DELETE OBJECT hDoc.
DELETE OBJECT hRoot.
DELETE OBJECT hNode.
COPY-LOB lcc TO FILE "test.log".