Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3974694
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:35:53+00:00 2026-05-20T04:35:53+00:00

Test.xml: <?xml version=1.0 encoding=UTF-8?> <node>line1 line2 line3</node> CF code: <cfset xmlfile = ExpandPath(test.xml)> <cffile

  • 0

Test.xml:

<?xml version="1.0" encoding="UTF-8"?>
<node>line1
line2
line3</node>

CF code:

<cfset xmlfile = ExpandPath("test.xml")>
<cffile action="read" file="#xmlfile#" variable="xmlstring">
<cffile action="write" file="test1.xml" output="#xmlstring#">

<cfset xmldoc = XmlParse(xmlstring)> 
<cfset xmltext = ToString(xmldoc)>
<cffile action="write" file="test2.xml" output="#xmltext#">

The input file test.xml file is in CRLF format, UTF-8 encoded, 77 bytes.
The first output file (test1.xml) is in CRLF format, ANSI encoded, 76 bytes.
The second output file (test2.xml) is in UNIX format, ANSI encoded, 71 bytes.

The contents of the XML node in the input file is line1 Chr(13)Chr(10) line2 Chr(13)Chr(10) line3 (whitespaces for readability).
The contents of the XML node in the first output file is the same as above.
The contents of the XML node in the second output file is line1 Chr(10) line2 Chr(10) line3.

Any ideas why the carriage return character Chr(13) was not preserved after the XmlParse/ToString sequence?

UPDATE:
The problem lies only with XmlParse. It’s not about ToString or cffile.
Here is a more relevant example – you can test for yourselves:

<cfsavecontent variable="xmlvar">
<nodes>
    <node>
line1
line2
line3
    </node>
</nodes>
</cfsavecontent>

<cfset vtext = "#xmlvar#">
<cfset vtext = Replace(vtext,Chr(10),'LF','All')>
<cfset vtext = Replace(vtext,Chr(13),'CR','All')>
<cfdump var = "#vtext#">
<!--- outputs CRLF<nodes>CRLF <node>CRLFline1CRLFline2CRLFline3CRLF </node>CRLF</nodes>CRLF --->
<cfset xmldoc = XmlParse(xmlvar)>
<cfset vtext = "#xmldoc.nodes.node.XmlText#">
<cfset vtext = Replace(vtext,Chr(10),'LF','All')>
<cfset vtext = Replace(vtext,Chr(13),'CR','All')>
<cfdump var = "#vtext#">
<!--- outputs LFline1LFline2LFline3LF --->
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:35:53+00:00Added an answer on May 20, 2026 at 4:35 am

    XML Parsers normalize the CR/LF to LF per the spec. To keep the CR/LF EOL use entity references. See below:

    <cfsavecontent variable="xmlvar">
    <nodes>
        <node>
          line1&#x000D;&#x000A;
          line2&#x000D;&#x000A;
          line3&#x000D;&#x000A;
        </node>
    </nodes>
    </cfsavecontent>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm editing XML element with the following XML: <?xml version=1.0 encoding=utf-8?> <!--Test XML with
i have the xml file like: <?xml version=1.0 encoding=utf-8 ?> <Config> <MetadataFormConfig FieldInternalName=Test> <Tabs>
I have the following xml file: <?xml version=1.0 encoding=utf-8?> <root> <phrase id=test><![CDATA[test]]></phrase> <phrase id=test0><![CDATA[test0]]></phrase>
I have the following XML file: <xml version=1.0 encoding=utf-8?> <Data> <Parameter1>1</Parameter1> </Data> I want
I have the next element <statement id =5> insert into TBTEMPLATES(CTDB_LAST_UPDATOR) values('<?xml version=1.0 encoding=UTF-8?><Interface
I have a style sheet like this <?xml version=1.0 encoding=utf-8?> <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:param
I'm reading an XML file that looks like this: <?xml version=1.0 encoding=utf-8?> <VehicleList> <Vehicle>
Consider the following css and html. <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML
<?xml version=1.0 encoding=UTF-8?> <form:Documents xmlns:form=http://www.abbyy.com/FlexiCapture/Schemas/Export/FormData.xsd xmlns:addData=http://www.abbyy.com/FlexiCapture/Schemas/Export/AdditionalFormData.xsd> <_Document_Definition_1:_Document_Definition_1 addData:ImagePath=C:\POC\Export\Test.pdf xmlns:_Document_Definition_1=http://www.abbyy.com/FlexiCapture/Schemas/Export/Document_Definition_1.xsd> <_Page_1> <_First_Name>John</_First_Name> <_Last_Name>Doe</_Last_Name> </_Page_1> </_Document_Definition_1:_Document_Definition_1>
if i parse this xml file: <?xml version=1.0 encoding=UTF-8?> <rootnode> <testnode info=Test1/> <testnode info=Test2/>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.