need to create simple XML file with namespace - how?

Calvin Crawford

New Member
I'd like to generate the following XML with ABL using the DOM method.

[FONT=r_ansi][FONT=r_ansi][FONT=r_ansi][FONT=r_ansi]<?xml version="1.0" ?>
<ns1:RecentNoonExchange2TestProcessRequest xmlns:ns1="http://xmlns.oracle.com/RecentNoonExchange2Test">
<ns1:TargetCurrency>USD</ns1:TargetCurrency>
</ns1:RecentNoonExchange2TestProcessRequest>
[/FONT]
[/FONT]
[/FONT]
[/FONT]
 
Code:
DEF VAR xdoc  AS HANDLE.
DEF VAR xroot AS HANDLE.
DEF VAR xnode AS HANDLE.
DEF VAR xtxt  AS HANDLE.
DEF VAR ret   AS LONGCHAR.


CREATE X-DOCUMENT xdoc.
CREATE X-NODEREF  xroot.
CREATE X-NODEREF  xnode.
CREATE X-NODEREF  xtxt.

xdoc:CREATE-NODE-NAMESPACE(xroot, 'http://xmlns.oracle.com/RecentNoonExchange2Test', 'ns1:RecentNoonExchange2TestProcessRequest', 'element').
xdoc:CREATE-NODE-NAMESPACE(xnode, 'http://xmlns.oracle.com/RecentNoonExchange2Test', 'ns1:TargetCurrency', 'element').
xdoc:CREATE-NODE(xtxt, '', 'text').

xroot:SET-ATTRIBUTE('xmlns:ns1', 'http://xmlns.oracle.com/RecentNoonExchange2Test').
xtxt:NODE-VALUE = 'USD'.

xdoc:APPEND-CHILD(xroot).
xroot:APPEND-CHILD(xnode).
xnode:APPEND-CHILD(xtxt).

xdoc:SAVE('longchar', ret).

DELETE OBJECT xnode.
DELETE OBJECT xroot.
DELETE OBJECT xdoc.

MESSAGE STRING(ret)
    VIEW-AS ALERT-BOX INFO BUTTONS OK.

I didn't expect set-attribute to be needed but it seems like it has to be there... what is the reason for which you prefer DOM over SAX-WRITER (other than an older version on which SAX isn't available).
 
Back
Top