I would like to know how to replace xmlns in WRITE-DATA-ELEMENT. Should I use WRITE-CHARACTERS instead of WRITE-DATA-ELEMENT ? Please see the attached document.
Does this work? It adds the attributes on the same line as the WRITE-DATA-ELEMENT(). You can change the namespace in the sax-attributes handle too.
DEF VAR hSAXWr AS HANDLE. def var hSaxAttr as handle. def var lcXML as longchar. CREATE SAX-WRITER hSAXWr. ASSIGN hSAXWr:FORMATTED = TRUE hSAXWr:ENCODING = "UTF-8" hSAXWr:STRICT = FALSE. create sax-attributes hSaxAttr. hSaxAttr:insert-attribute('prop', 'EXTREF'). hSAXWr:SET-OUTPUT-DESTINATION('longchar', lcXML). hSAXWr:START-DOCUMENT(). hSAXWr:START-ELEMENT('Item'). hSAXWr:WRITE-DATA-ELEMENT('Dom', 'test', ?, hSaxAttr). hSAXWr:WRITE-DATA-ELEMENT('Dom', 'marjo', ?, hSaxAttr). hSaxAttr:update-attribute('prop', 'EXTGO'). hSAXWr:END-ELEMENT('Item'). hSAXWr:END-DOCUMENT(). message string(lcxml) view-as alert-box.
It could look something like this:
DEF VAR hSAXWr AS HANDLE.
CREATE SAX-WRITER hSAXWr.
ASSIGN hSAXWr:FORMATTED = TRUE
hSAXWr:ENCODING = "UTF-8"
hSAXWr:STRICT = FALSE.
hSAXWr:SET-OUTPUT-DESTINATION('file', 'c:\temp\bronco.xml').
hSAXWr:START-DOCUMENT().
hSAXWr:START-ELEMENT('Item').
hSAXWr:START-ELEMENT('Dom').
hSAXWr:insert-attribute("prop", "EXTREF").
hSAXWr:write-characters("test").
hSAXWr:END-ELEMENT('Dom').
hSAXWr:START-ELEMENT('Dom').
hSAXWr:insert-attribute("prop", "EXTGO").
hSAXWr:write-characters("marjo").
hSAXWr:END-ELEMENT('Dom').
hSAXWr:END-ELEMENT('Item').
hSAXWr:END-DOCUMENT().
For more info about adding attributes please check the OpenEdge Documentation:
documentation.progress.com/.../index.html
I think this would help more in achieving the desired behavior.
Thanks but it's not what I am looking for. I want the result on the same line ... I can't belive there is no way to do that ...
Unfortunately, I did ... the prefix is added but somewhere else ... I am pretty sure I am doing something wrong but I can't figure it out. I think I will open a case. Thanks
Does this work? It adds the attributes on the same line as the WRITE-DATA-ELEMENT(). You can change the namespace in the sax-attributes handle too.
DEF VAR hSAXWr AS HANDLE. def var hSaxAttr as handle. def var lcXML as longchar. CREATE SAX-WRITER hSAXWr. ASSIGN hSAXWr:FORMATTED = TRUE hSAXWr:ENCODING = "UTF-8" hSAXWr:STRICT = FALSE. create sax-attributes hSaxAttr. hSaxAttr:insert-attribute('prop', 'EXTREF'). hSAXWr:SET-OUTPUT-DESTINATION('longchar', lcXML). hSAXWr:START-DOCUMENT(). hSAXWr:START-ELEMENT('Item'). hSAXWr:WRITE-DATA-ELEMENT('Dom', 'test', ?, hSaxAttr). hSAXWr:WRITE-DATA-ELEMENT('Dom', 'marjo', ?, hSaxAttr). hSaxAttr:update-attribute('prop', 'EXTGO'). hSAXWr:END-ELEMENT('Item'). hSAXWr:END-DOCUMENT(). message string(lcxml) view-as alert-box.
Thank you very much Peter, it is working perfectly !!!