Remove XML Declaration (Prolong)

Miss_Dev

New Member
Hi , I have a program that creates an XML file . How can I stop the xml declaration from being added to the xml by default ?

xml declaration
<?xml version="1.0" encoding="UTF-8" ?>

code spinet
DEFINE VARIABLE h AS HANDLE NO-UNDO.
DEFINE VARIABLE v_ptrXML AS MEMPTR NO-UNDO.
DEFINE VARIABLE o_hXDoc AS HANDLE NO-UNDO.
CREATE SAX-WRITER h.
define variable v_nameFile as character no-undo.

ASSIGN v_nameFile = "R:\task\ashus\abc.xml" .

h:SET-OUTPUT-DESTINATION("MEMPTR", v_ptrXML).

h:FORMATTED = TRUE.
h:FRAGMENT = TRUE.

h:START-DOCUMENT().

h:START-ELEMENT("customer").
h:WRITE-DATA-ELEMENT("name","Ahus").
h:WRITE-DATA-ELEMENT("addr","Address1").
h:WRITE-DATA-ELEMENT("addr2","").
h:WRITE-DATA-ELEMENT("addr3","Adress3").
h:WRITE-DATA-ELEMENT("newline","~n").
h:WRITE-DATA-ELEMENT("spaces"," ").
h:WRITE-DATA-ELEMENT("dob", "25/02/1990").
h:END-ELEMENT("customer").

h:END-DOCUMENT().

DELETE OBJECT h.
ASSIGN h = ? .

CREATE X-DOCUMENT o_hXDoc.

o_hXDoc:LOAD("MEMPTR", v_ptrXML, FALSE) .
o_hXDoc:save("file",v_nameFile) NO-ERROR.


=============================================================================

OUTPUT
<?xml version="1.0" encoding="UTF-8" ?>
<customer>
<name>Ahus</name>
<addr>Address1</addr>
<addr2/>
<addr3>Adress3</addr3>
<newline>
</newline>
<spaces> </spaces>
<dob>25/02/1990</dob>
</customer>
 

Cecil

19+ years progress programming and still learning.
This is more of a hack because of the limitation of the X-DOCUMENT handler.

Code:
DEFINE VARIABLE h AS HANDLE NO-UNDO.
DEFINE VARIABLE v_ptrXML AS MEMPTR NO-UNDO.
DEFINE VARIABLE o_hXDoc AS HANDLE NO-UNDO.

CREATE SAX-WRITER h.
define variable v_nameFile as character no-undo.
define variable xmlOutput  as longchar no-undo.
define variable xmlOutputNoDec  as longchar no-undo.


ASSIGN v_nameFile = "abc.xml" .

h:SET-OUTPUT-DESTINATION("MEMPTR", v_ptrXML).

h:FORMATTED = TRUE.
h:FRAGMENT = TRUE.

h:START-DOCUMENT().

h:START-ELEMENT("customer").
h:WRITE-DATA-ELEMENT("name","Ahus").
h:WRITE-DATA-ELEMENT("addr","Address1").
h:WRITE-DATA-ELEMENT("addr2","").
h:WRITE-DATA-ELEMENT("addr3","Adress3").
h:WRITE-DATA-ELEMENT("newline","~n").
h:WRITE-DATA-ELEMENT("spaces"," ").
h:WRITE-DATA-ELEMENT("dob", "25/02/1990").
h:END-ELEMENT("customer").

h:END-DOCUMENT().

DELETE OBJECT h.
ASSIGN h = ? .

CREATE X-DOCUMENT o_hXDoc.

o_hXDoc:LOAD("MEMPTR", v_ptrXML, FALSE) .

o_hXDoc:save("longchar",xmlOutput) NO-ERROR.

copy-lob from object xmlOutput starting at index(xmlOutput, '?>') + 3 to file v_nameFile.
copy-lob from object xmlOutput starting at index(xmlOutput, '?>') + 3 to object xmlOutputNoDec.

message string(xmlOutputNoDec).
 

peterjudge

Member
In some later OE versions (12.3 I think, and the roughly-equivalent 11.7.8 update), the INDEX() function has been enhanced to support using a MEMPTR as a source. This means you don't need to copy the MEMPTR to a LONGCHAR and back.

C-like:
define variable iPos as int64 no-undo.

iPos = index(v_ptrXML, '?>').
   
/* you may want to check if the next character is CR or LF and act accordingly. */  
if get-byte(v_ptrXML, iPos + 1)    = 13 then
  iPos = iPos + 3.
if get-byte(v_ptrXML, iPos + 1)    = 10 then
  iPos = iPos + 2.
   
copy-lob from object v_ptrXML starting at iPos to file v_nameFile.
 

Cecil

19+ years progress programming and still learning.
In some later OE versions (12.3 I think, and the roughly-equivalent 11.7.8 update), the INDEX() function has been enhanced to support using a MEMPTR as a source. This means you don't need to copy the MEMPTR to a LONGCHAR and back.

C-like:
define variable iPos as int64 no-undo.

iPos = index(v_ptrXML, '?>').
  
/* you may want to check if the next character is CR or LF and act accordingly. */ 
if get-byte(v_ptrXML, iPos + 1)    = 13 then
  iPos = iPos + 3.
if get-byte(v_ptrXML, iPos + 1)    = 10 then
  iPos = iPos + 2.
  
copy-lob from object v_ptrXML starting at iPos to file v_nameFile.
Thanks Peter. I did not know about this.
I've been wanting functionality since 2004.
I did noticed the R-index function does not support memptr datatype, possibly their was some technical reason.
 
Top