ColdFusion: Invalid XML Control Character (Hexadecimal)

I am trying to create an xml object using . I formatted all the data with XMLFormat().
There are some invalid characters in the XML, such as’»’. I added this character to the xml doctype as follows:


The HTML text format is not Very good, but most of them are applicable to my code. But there are some control characters in some texts. I get the following error:

Invalid XML characters found in the element content of the document ( Unicode: 0x13).

I tried to add unicode to the doctype, I tried this solution. Neither worked…

This is a valid cfscript code, used to clean up our XML, there are two methods, one is to clear higher international characters, and the other is to clear and destroy us Lower ASCII characters of XML, if you find more characters, just expand the filter rules.

 
function cleanHighAscii(text){< br /> var buffer = createObject("java", "java.lang.StringBuffer").init();
var pattern = createObject("java", "java.util.regex.Pattern").compile (javaCast( "string", "[^-]" ));
var matcher = pattern.Matcher(javaCast( "string", text));

while (matcher.find()){
var value = matcher.group();
var asciiValue = asc(value);

if ((asciiValue == 8220) OR (asciiValue == 8221))
value = """";
else if ((asciiValue == 8216) || (asciiValue == 8217))
value = "'";
else if (asciiValue == 8230)
value = "...";
else
value = "&###asciiValue# ;";

matcher.AppendReplacement(buffer, javaCast( "string", value ));
}

matcher.AppendTail(buffer);
return buffer.ToString();
}

function removeSubAscii(text){

return rereplaceNoCase(text, "","&### 26#;", "all");
}

function XMLSafe(text){
text = cleanHighAscii(text);
text = removeSubAscii(text) ;
return text;
}

Other posisbilty is user CF10 function encodeForXML():

https://learn .adobe.com/wiki/display/coldfusionen/EncodeForXML

Or use the CFAPI attached to CF10 directly, or from OWA SP website https://www.owasp.org/index.php/ESAPI_Overview add ESAPI jar to your old CF:

var esapi = createObject("java", " org.owasp.esapi.ESAPI");
var esapiEncoder = esapi.encoder();
return esapiEncoder.encodeForXML(text);

I am trying to create an xml object using . I formatted all the data with XMLFormat().
There are some invalid characters in XML, such as’»’. I added this character to the xml doctype as follows Shown:


HTML text format is not very good, but most of them are suitable for mine Code. But there are some control characters in some text. I receive the following error:

An invalid XML character (Unicode: 0x13) was found in the element content of the document.

I tried to add unicode to the doctype, I tried this solution. Neither worked…

This is valid cfscript code, use To clean up our XML, there are two methods, one is to clear the higher international characters, and the other is to clear only the lower ASCII characters that destroy our XML. If you find more characters, just expand the filter rules.

< /p>

 
function cleanHighAscii(text){
var buffer = createObject("java", "java.lang.StringBuffer").init( );
var pattern = createObject("java", "java.util.regex.Pattern").compile(javaCast( "string", "[^-]" ));
var matcher = pattern.Matcher(javaCast( "string", text ));

while(matcher.find()){
var value = matcher.group();
var asciiValue = asc(value);
< br /> if ((asciiValue == 8220) OR (asciiValue == 8221))
value = """";
else if ((asciiValue == 8216) || (asciiValue == 8217 ))
value = "'";
else if (asciiValue == 8230)
value = "...";
else
value = "&# ##asciiValue#;";

matcher.AppendReplacement(buffer, javaCast( "string", value ));
}

matcher.AppendTail(buffer) ;
return buffer.ToString();
}

function removeSubAscii(text){

return rereplaceNoCase(text, ""," &###26#;", "all");
}

function XMLSafe(text){
text = cleanHighAscii(text);
text = removeSubAscii(text);
return text;
}

Other posisbilty is user CF10 function encodeForXML():

https://learn.adobe.com/wiki/display/coldfusionen/EncodeForXML

Or use the CFAPI attached to CF10 directly, or add ESAPI jar to your old CF from the OWASP website https://www.owasp.org/index.php/ESAPI_Overview:

var esapi = createObject("java", "org.owasp.esapi.ESAPI");
var esapiEncoder = esapi.encoder();
return esapiEncoder.encodeForXML(text);

Leave a Comment

Your email address will not be published.