<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: How to strip invalid XML characters</title>
	<atom:link href="http://benjchristensen.com/2008/02/07/how-to-strip-invalid-xml-characters/feed/" rel="self" type="application/rss+xml" />
	<link>http://benjchristensen.com/2008/02/07/how-to-strip-invalid-xml-characters/</link>
	<description></description>
	<lastBuildDate>Fri, 25 May 2012 19:08:30 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: psd2magento</title>
		<link>http://benjchristensen.com/2008/02/07/how-to-strip-invalid-xml-characters/#comment-569</link>
		<dc:creator><![CDATA[psd2magento]]></dc:creator>
		<pubDate>Wed, 25 Apr 2012 09:10:10 +0000</pubDate>
		<guid isPermaLink="false">http://benjchristensen.wordpress.com/?p=54#comment-569</guid>
		<description><![CDATA[I needed php code to validate xml code. Thanks for the post!]]></description>
		<content:encoded><![CDATA[<p>I needed php code to validate xml code. Thanks for the post!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Diego</title>
		<link>http://benjchristensen.com/2008/02/07/how-to-strip-invalid-xml-characters/#comment-513</link>
		<dc:creator><![CDATA[Diego]]></dc:creator>
		<pubDate>Tue, 05 Jul 2011 09:41:07 +0000</pubDate>
		<guid isPermaLink="false">http://benjchristensen.wordpress.com/?p=54#comment-513</guid>
		<description><![CDATA[Thanks! Same thing, using replaceAll instead of char walking:
	String invalidXmlPattern = &quot;[^&quot;
		+ &quot;\\u0009\\u000A\\u000D&quot;
		+ &quot;\\u0020-\\uD7FF&quot; 
		+ &quot;\\uE000-\\uFFFD&quot;
		+ &quot;\\u10000-\\u10FFFF&quot;
		+ &quot;]+&quot;;		
	xml = xml.replaceAll(invalidXmlPattern, &quot; &quot;);]]></description>
		<content:encoded><![CDATA[<p>Thanks! Same thing, using replaceAll instead of char walking:<br />
	String invalidXmlPattern = &#8220;[^"<br />
		+ "\\u0009\\u000A\\u000D"<br />
		+ "\\u0020-\\uD7FF"<br />
		+ "\\uE000-\\uFFFD"<br />
		+ "\\u10000-\\u10FFFF"<br />
		+ "]+&#8221;;<br />
	xml = xml.replaceAll(invalidXmlPattern, &#8221; &#8220;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tyler Sullivan</title>
		<link>http://benjchristensen.com/2008/02/07/how-to-strip-invalid-xml-characters/#comment-483</link>
		<dc:creator><![CDATA[Tyler Sullivan]]></dc:creator>
		<pubDate>Fri, 18 Mar 2011 21:56:50 +0000</pubDate>
		<guid isPermaLink="false">http://benjchristensen.wordpress.com/?p=54#comment-483</guid>
		<description><![CDATA[Oh well. The second one should be &quot;&amp; amp;&quot; without the space]]></description>
		<content:encoded><![CDATA[<p>Oh well. The second one should be &#8220;&amp; amp;&#8221; without the space</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tyler Sullivan</title>
		<link>http://benjchristensen.com/2008/02/07/how-to-strip-invalid-xml-characters/#comment-482</link>
		<dc:creator><![CDATA[Tyler Sullivan]]></dc:creator>
		<pubDate>Fri, 18 Mar 2011 21:56:00 +0000</pubDate>
		<guid isPermaLink="false">http://benjchristensen.wordpress.com/?p=54#comment-482</guid>
		<description><![CDATA[Another victim of the comments system.  Lets try this.
&lt;code&gt;&lt;pre&gt;e.g. strtr($xml,array(&#039;&amp; &#039;=&gt;&#039;&amp; &#039;));&lt;/pre&gt;&lt;/code&gt;]]></description>
		<content:encoded><![CDATA[<p>Another victim of the comments system.  Lets try this.<br />
<code>
<pre>e.g. strtr($xml,array('&amp; '=&gt;'&amp; '));</pre>
<p></code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tyler Sullivan</title>
		<link>http://benjchristensen.com/2008/02/07/how-to-strip-invalid-xml-characters/#comment-481</link>
		<dc:creator><![CDATA[Tyler Sullivan]]></dc:creator>
		<pubDate>Fri, 18 Mar 2011 21:54:10 +0000</pubDate>
		<guid isPermaLink="false">http://benjchristensen.wordpress.com/?p=54#comment-481</guid>
		<description><![CDATA[Another option in php is to use strtr to replace bad characters with equivalents.

e.g. strtr($xml,array(&#039;&amp; &#039;=&gt;&#039;&amp; &#039;));

I am sure other languages have tr fuction equivalents.]]></description>
		<content:encoded><![CDATA[<p>Another option in php is to use strtr to replace bad characters with equivalents.</p>
<p>e.g. strtr($xml,array(&#8216;&amp; &#8216;=&gt;&#8217;&amp; &#8216;));</p>
<p>I am sure other languages have tr fuction equivalents.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Antonio Lagnada</title>
		<link>http://benjchristensen.com/2008/02/07/how-to-strip-invalid-xml-characters/#comment-274</link>
		<dc:creator><![CDATA[Antonio Lagnada]]></dc:creator>
		<pubDate>Wed, 18 Mar 2009 19:48:55 +0000</pubDate>
		<guid isPermaLink="false">http://benjchristensen.wordpress.com/?p=54#comment-274</guid>
		<description><![CDATA[String str = &quot;contains invalid chars&quot;;
String stripped = str.replaceAll(&quot;[^\\u0009\\u000a\\u000d\\u0020-\\ud7ff\\e0000-\\ufffd]&quot;, &quot;&quot;)]]></description>
		<content:encoded><![CDATA[<p>String str = &#8220;contains invalid chars&#8221;;<br />
String stripped = str.replaceAll(&#8220;[^\\u0009\\u000a\\u000d\\u0020-\\ud7ff\\e0000-\\ufffd]&#8220;, &#8220;&#8221;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Christensen</title>
		<link>http://benjchristensen.com/2008/02/07/how-to-strip-invalid-xml-characters/#comment-256</link>
		<dc:creator><![CDATA[Ben Christensen]]></dc:creator>
		<pubDate>Sun, 17 Aug 2008 01:14:02 +0000</pubDate>
		<guid isPermaLink="false">http://benjchristensen.wordpress.com/?p=54#comment-256</guid>
		<description><![CDATA[The original is Java code. Thank you for the code you provided!]]></description>
		<content:encoded><![CDATA[<p>The original is Java code. Thank you for the code you provided!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anthony</title>
		<link>http://benjchristensen.com/2008/02/07/how-to-strip-invalid-xml-characters/#comment-255</link>
		<dc:creator><![CDATA[anthony]]></dc:creator>
		<pubDate>Sat, 16 Aug 2008 23:52:51 +0000</pubDate>
		<guid isPermaLink="false">http://benjchristensen.wordpress.com/?p=54#comment-255</guid>
		<description><![CDATA[there is something broken about this comment posting script, that code, is _not_ what I posted ;)]]></description>
		<content:encoded><![CDATA[<p>there is something broken about this comment posting script, that code, is _not_ what I posted <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anthony</title>
		<link>http://benjchristensen.com/2008/02/07/how-to-strip-invalid-xml-characters/#comment-254</link>
		<dc:creator><![CDATA[anthony]]></dc:creator>
		<pubDate>Sat, 16 Aug 2008 23:51:24 +0000</pubDate>
		<guid isPermaLink="false">http://benjchristensen.wordpress.com/?p=54#comment-254</guid>
		<description><![CDATA[I&#039;ll try one more time, cut my post short last time, if it doesn&#039;t work this time... oh well.

function strip_invalid_xml_chars2( &amp;$in )
{
	$out = &quot;&quot;;	
	$length = strlen($in);
	for ( $i = 0; $i = 0x20 &amp;&amp; $current = 0xE000 &amp;&amp; $current = 0x10000 &amp;&amp; $current &lt;= 0x10FFFF):
				// valid so leave &quot;as is&quot;
				break;
			default:
				// invalid, so we set this char to a space
				$in[$i] = &quot; &quot;; 
			break;
		}	
	}
	// NOTE: doesn&#039;t return a value as we worked purely on 
	// the string passed by reference, so don&#039;t try catching a return value	
}]]></description>
		<content:encoded><![CDATA[<p>I&#8217;ll try one more time, cut my post short last time, if it doesn&#8217;t work this time&#8230; oh well.</p>
<p>function strip_invalid_xml_chars2( &amp;$in )<br />
{<br />
	$out = &#8220;&#8221;;<br />
	$length = strlen($in);<br />
	for ( $i = 0; $i = 0&#215;20 &amp;&amp; $current = 0xE000 &amp;&amp; $current = 0&#215;10000 &amp;&amp; $current &lt;= 0x10FFFF):<br />
				// valid so leave &#8220;as is&#8221;<br />
				break;<br />
			default:<br />
				// invalid, so we set this char to a space<br />
				$in[$i] = &#8221; &#8220;;<br />
			break;<br />
		}<br />
	}<br />
	// NOTE: doesn&#8217;t return a value as we worked purely on<br />
	// the string passed by reference, so don&#8217;t try catching a return value<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anthony</title>
		<link>http://benjchristensen.com/2008/02/07/how-to-strip-invalid-xml-characters/#comment-253</link>
		<dc:creator><![CDATA[anthony]]></dc:creator>
		<pubDate>Sat, 16 Aug 2008 23:49:15 +0000</pubDate>
		<guid isPermaLink="false">http://benjchristensen.wordpress.com/?p=54#comment-253</guid>
		<description><![CDATA[I assume that comment was a PHP version, so you want something like this:
&lt;?php
/**
* Strip bad xml chars
* @author phpzone
* @param string $in String passed by reference
* phpzone.co.uk
*/
function strip_invalid_xml_chars2( &amp;$in )
{
	$out = &quot;&quot;;	
	$length = strlen($in);
	for ( $i = 0; $i = 0x20 &amp;&amp; $current = 0xE000 &amp;&amp; $current = 0x10000 &amp;&amp; $current ]]></description>
		<content:encoded><![CDATA[<p>I assume that comment was a PHP version, so you want something like this:<br />
&lt;?php<br />
/**<br />
* Strip bad xml chars<br />
* @author phpzone<br />
* @param string $in String passed by reference<br />
* phpzone.co.uk<br />
*/<br />
function strip_invalid_xml_chars2( &amp;$in )<br />
{<br />
	$out = &#8220;&#8221;;<br />
	$length = strlen($in);<br />
	for ( $i = 0; $i = 0&#215;20 &amp;&amp; $current = 0xE000 &amp;&amp; $current = 0&#215;10000 &amp;&amp; $current </p>
]]></content:encoded>
	</item>
</channel>
</rss>

