This discussion is archived
3 Replies Latest reply: Aug 12, 2013 1:30 PM by KnightOfBlueArmor RSS

XMLSerialize indent end of line marker

paul zip Newbie
Currently Being Moderated

In 11g you can specify to pretty print XML when serializing using the indent clause of XMLSerialize.  The trouble is this is formatted using the UNIX end of line marker, Line Feed = #10, even if Oracle is running under Window Server (windows uses Carriage Return + Line Feed = #13#10).  This is causing problems when XML docs are delivered to users on Windows machines, who open it in notepad or similar - it means the data isn't visualised properly (not pretty printed) and they see the LF as a "box" character, which confuses them.

 

declare

  vFileContents CLOB;

  vXMLData XMLType;

begin

...

  select XMLSerialize(document vXMLData as CLOB indent)

  into vFileContents

  from dual;

...

  -- Code to output vFileContents to file.

end;

/

 

Is there any setting (session or DB) to specify CRLF as the default end of line marker, rather than having to do a search and replace on every document?

  • 1. Re: XMLSerialize indent end of line marker
    odie_63 Guru
    Currently Being Moderated

    Is there any setting (session or DB) to specify CRLF as the default end of line marker, rather than having to do a search and replace on every document?

    Maybe it's a bug, maybe it's been made like that on purpose.

    Anyhow, I think the determining factor is the way the content is written to file.

    How is that part achieved in your code?

     

    For instance, UTL_FILE automatically converts LF to CRLF on Windows platforms, provided the file is written in character mode.

    If binary mode is used then no conversion takes place.

     

    If you're using DBMS_XSLPROCESSOR.clob2file(),  it calls UTL_FILE in binary mode internally (so that a different output character set may be specified). So, no conversion in this case.

    The same goes for DBMS_XMLDOM.writeToFile() since it is based on DBMS_XSLPROCESSOR.

     

    Second question is : how are the files transferred to user machines ?

  • 2. Re: XMLSerialize indent end of line marker
    paul zip Newbie
    Currently Being Moderated

    odie_63 wrote:

     

    Maybe it's a bug, maybe it's been made like that on purpose.

    Anyhow, I think the determining factor is the way the content is written to file.

    How is that part achieved in your code?

    The data is chunk written to a file using UTL_FILE and PUT_RAW, using filetype mode AB or WB (append byte or write byte mode), so no character conversion takes place.

     

    Second question is : how are the files transferred to user machines ?

     

    Once the file has been written as mentioned above, they are copied manually - so again no alteration is made to the output.

  • 3. Re: XMLSerialize indent end of line marker
    KnightOfBlueArmor Newbie
    Currently Being Moderated

    Perhaps you could try REGEXP_REPLACE on the serialized output, replacing '\n' with '\r\n'.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points