ColdFusion XMLFormat () does not convert all characters

I am using XMLFormat () to encode some text for an XML document. However, when I go to read the XML file that I created, I get an invalid character error. Why is XMLFormat () incorrectly encoding all characters?

I am launching CF8.

+3
source share
6 answers

Are you sure you want to output the file in the correct encoding? You can't just do

<cffile action="write" file="foo.xml" output="#xml#" />

as a result, it will most likely be different from the character set your XML is in. Unless otherwise specified (by coding declaration), the XML files are treated as UTF-8, and you should do:

<cffile action="write" file="foo.xml" output="#xml#" charset="utf-8" />
<!--- and --->
<cffile action="read" file="foo.xml" variable="xml" charset="utf-8" />
+5
source

, XMLFormat. , , , ...

  <cfset myText = xmlFormat(myText)>

  <cfscript>
      i = 0;
      tmp = '';
      while(ReFind('[^\x00-\x7F]',myText,i,false))
      {
        i = ReFind('[^\x00-\x7F]',myText,i,false); // discover high chr and save it numeric string position.
        tmp = '&##x#FormatBaseN(Asc(Mid(myText,i,1)),16)#;'; // obtain the high chr and convert it to a hex numeric chr.
        myText = Insert(tmp,myText,i); // insert the new hex numeric chr into the string.
        myText = RemoveChars(myText,i,1); // delete the redundant high chr from string.
        i = i+Len(tmp); // adjust the loop scan for the new chr placement, then continue the loop.
      }
      return myText;
  </cfscript>
+5

< cfprocessingdirective pageencoding = "utf-8" > .

0

XML , - .

<cfheader name="Content-Disposition" charset="utf-8" value="attachment; filename=export.xml">
<cfcontent variable="#someXMLPacket#" type="text/xml"  reset="true">

, , - (ala REST),

<cfheader charset="utf-8">
<cfcontent variable="#someXMLPacket#" type="text/xml"  reset="true">

,

0

, XMLFormat - . , [].

, XML, XMLFormat.

, (- ) -, ascii, 255, , .

0

, , , - .

xml, , ...

0

Source: https://habr.com/ru/post/1722149/


All Articles