Highlighted

CFFile write ' charset UTF-8

New Here ,
Dec 07, 2017

Copy link to clipboard

Copied

I'm attempting to write a string to an XML file using CFFile.
The XML file must have apostrophes expressed as "'" once complete.

I'm using <cffile action="write" file="#VDJ8databasepath#databaseNew.xml" output="#XmlString#" addnewline="no" charset="utf-8"> to write the string to a file.

I can change the string to represent apostrophes as " ' " or "&apos;" but when I write it to file, apostrophes are written as either " ' " or "&apos;". As you can see, when the string contains apostrophes represented as "&apos;" CFFile encodes the "&" character as "&" but when the string contains apostrophes represented as " ' " it does not encode them at all and simply leaves them as " ' ".


Any ideas how to get my apostrophes written by CFFile as  "&apos;"?

Views

322

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

CFFile write ' charset UTF-8

New Here ,
Dec 07, 2017

Copy link to clipboard

Copied

I'm attempting to write a string to an XML file using CFFile.
The XML file must have apostrophes expressed as "&apos;" once complete.

I'm using <cffile action="write" file="#VDJ8databasepath#databaseNew.xml" output="#XmlString#" addnewline="no" charset="utf-8"> to write the string to a file.

I can change the string to represent apostrophes as " ' " or "&apos;" but when I write it to file, apostrophes are written as either " ' " or "&apos;". As you can see, when the string contains apostrophes represented as "&apos;" CFFile encodes the "&" character as "&" but when the string contains apostrophes represented as " ' " it does not encode them at all and simply leaves them as " ' ".


Any ideas how to get my apostrophes written by CFFile as  "&apos;"?

Views

323

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 07, 2017 0
Adobe Community Professional ,
Dec 07, 2017

Copy link to clipboard

Copied

Might using writebinary instead help? I can’t test it at the moment.

/charlie

/Charlie (server troubleshooter, carehart.org)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 07, 2017 0
New Here ,
Dec 07, 2017

Copy link to clipboard

Copied

Thanks for responding Charlie. Can't quite see how writing as binary will make my file have the correct format. I did try it as it's new for me, but as expected, I couldn't get anything other than binary in the file. Might be taking you out of context here as I'm a bit rusty with the cffile, but just cant see how to make it work with writebinary.

Thanks anyway.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 07, 2017 0
Adobe Community Professional ,
Dec 07, 2017

Copy link to clipboard

Copied

It was a shot in the dark. Sorry.

/charlie

/Charlie (server troubleshooter, carehart.org)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 07, 2017 0
Adobe Community Professional ,
Dec 08, 2017

Copy link to clipboard

Copied

Try this:

<cfset content = "y's x's z & b's a's c">

<cfsavecontent variable="testString"><?xml version="1.0" encoding="UTF-8"?>

    <element>

    <cfoutput>#xmlFormat(content)#</cfoutput>

    </element>

</cfsavecontent>

<cffile action="write" file="#VDJ8databasepath#testFile.xml" output="#testString#">

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 08, 2017 0
web-eng LATEST
New Here ,
Dec 08, 2017

Copy link to clipboard

Copied

Hey Charlie,

before I start asking questions on the forum, I have to spend hours trying to find my own solution and only really want to use the forum as a last resort, at which point, shots in the dark are greatly appreciated, so please don't apologise too much and thanks for taking the time.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 08, 2017 0