<?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/"
		>
<channel>
	<title>Comments on: Safely cleaning HTML with strip_tags in C#</title>
	<atom:link href="http://www.dijksterhuis.org/safely-cleaning-html-with-strip_tags-in-csharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dijksterhuis.org/safely-cleaning-html-with-strip_tags-in-csharp/</link>
	<description>Information, news about programming in C#</description>
	<lastBuildDate>Sun, 21 Feb 2010 16:48:33 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Miguel</title>
		<link>http://www.dijksterhuis.org/safely-cleaning-html-with-strip_tags-in-csharp/comment-page-1/#comment-1355</link>
		<dc:creator>Miguel</dc:creator>
		<pubDate>Thu, 17 Sep 2009 13:24:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.dijksterhuis.org/?p=758#comment-1355</guid>
		<description>Hello,

I have been using this code and I really like it.
I wonder if you ever did the following:

A method that creates an excerpt of a string containing HTML code without breaking tags.

Thanks,
Miguel</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>I have been using this code and I really like it.<br />
I wonder if you ever did the following:</p>
<p>A method that creates an excerpt of a string containing HTML code without breaking tags.</p>
<p>Thanks,<br />
Miguel</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mikhail</title>
		<link>http://www.dijksterhuis.org/safely-cleaning-html-with-strip_tags-in-csharp/comment-page-1/#comment-1063</link>
		<dc:creator>mikhail</dc:creator>
		<pubDate>Fri, 10 Jul 2009 17:42:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.dijksterhuis.org/?p=758#comment-1063</guid>
		<description>&gt; Ben Drury

this is a new Csharp syntax, try to replace

MatchEvaluator HrefMatch = m =&gt; m.Groups[1].Value + &quot;href..;,;..&quot; + m.Groups[2].Value;
MatchEvaluator ClassMatch = m =&gt; m.Groups[1].Value + &quot;class..;,;..&quot; + m.Groups[2].Value;
MatchEvaluator UnsafeMatch = m =&gt; m.Groups[1].Value + m.Groups[4].Value;

for this

MatchEvaluator HrefMatch = delegate(Match m) { return (m.Groups[1].Value + &quot;href..;,;..&quot; + m.Groups[2].Value); };
MatchEvaluator ClassMatch = delegate(Match m) { return (m.Groups[1].Value + &quot;class..;,;..&quot; + m.Groups[2].Value); };
MatchEvaluator UnsafeMatch = delegate(Match m) { return (m.Groups[1].Value + m.Groups[4].Value); };</description>
		<content:encoded><![CDATA[<p>&gt; Ben Drury</p>
<p>this is a new Csharp syntax, try to replace</p>
<p>MatchEvaluator HrefMatch = m =&gt; m.Groups[1].Value + &#8220;href..;,;..&#8221; + m.Groups[2].Value;<br />
MatchEvaluator ClassMatch = m =&gt; m.Groups[1].Value + &#8220;class..;,;..&#8221; + m.Groups[2].Value;<br />
MatchEvaluator UnsafeMatch = m =&gt; m.Groups[1].Value + m.Groups[4].Value;</p>
<p>for this</p>
<p>MatchEvaluator HrefMatch = delegate(Match m) { return (m.Groups[1].Value + &#8220;href..;,;..&#8221; + m.Groups[2].Value); };<br />
MatchEvaluator ClassMatch = delegate(Match m) { return (m.Groups[1].Value + &#8220;class..;,;..&#8221; + m.Groups[2].Value); };<br />
MatchEvaluator UnsafeMatch = delegate(Match m) { return (m.Groups[1].Value + m.Groups[4].Value); };</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt B</title>
		<link>http://www.dijksterhuis.org/safely-cleaning-html-with-strip_tags-in-csharp/comment-page-1/#comment-1057</link>
		<dc:creator>Matt B</dc:creator>
		<pubDate>Wed, 08 Jul 2009 10:35:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.dijksterhuis.org/?p=758#comment-1057</guid>
		<description>Apologies it seems some of my HTML was stripped out :-)

here are the corrections:

1) use this as a string: h1 style=&quot;clear:none&quot; The Miners Strike of 1984 h1 (I have removed the angular brackets but you get the idea)

2) I get the result:

h1:none&quot; The Miners Strike of 1984 /h1

Cheers</description>
		<content:encoded><![CDATA[<p>Apologies it seems some of my HTML was stripped out <img src='http://www.dijksterhuis.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>here are the corrections:</p>
<p>1) use this as a string: h1 style=&#8221;clear:none&#8221; The Miners Strike of 1984 h1 (I have removed the angular brackets but you get the idea)</p>
<p>2) I get the result:</p>
<p>h1:none&#8221; The Miners Strike of 1984 /h1</p>
<p>Cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt B</title>
		<link>http://www.dijksterhuis.org/safely-cleaning-html-with-strip_tags-in-csharp/comment-page-1/#comment-1056</link>
		<dc:creator>Matt B</dc:creator>
		<pubDate>Wed, 08 Jul 2009 10:15:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.dijksterhuis.org/?p=758#comment-1056</guid>
		<description>Hi Martijn.
Thanks for the class, very useful. I have, however, found an issue:

use this as a string: &quot;any old text goes here&quot;

my allowed html elements are: p, i, b, h1 (i.e. h1 tags ARE allowed)

When I pass them through to the StripTagsAndAttributes method, I get the result:

&quot;any old text goes here&quot;

I know the stripping of attributes is responsible for this and I should use the StripTags method instead but if h1 is in my allowed list shouldn&#039;t the StripTagsAndAttributes method ignore all attributes associated with this tag?

Cheers</description>
		<content:encoded><![CDATA[<p>Hi Martijn.<br />
Thanks for the class, very useful. I have, however, found an issue:</p>
<p>use this as a string: &#8220;any old text goes here&#8221;</p>
<p>my allowed html elements are: p, i, b, h1 (i.e. h1 tags ARE allowed)</p>
<p>When I pass them through to the StripTagsAndAttributes method, I get the result:</p>
<p>&#8220;any old text goes here&#8221;</p>
<p>I know the stripping of attributes is responsible for this and I should use the StripTags method instead but if h1 is in my allowed list shouldn&#8217;t the StripTagsAndAttributes method ignore all attributes associated with this tag?</p>
<p>Cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Drury</title>
		<link>http://www.dijksterhuis.org/safely-cleaning-html-with-strip_tags-in-csharp/comment-page-1/#comment-893</link>
		<dc:creator>Ben Drury</dc:creator>
		<pubDate>Tue, 19 May 2009 14:38:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.dijksterhuis.org/?p=758#comment-893</guid>
		<description>Great procedure, thanks for developing.  I&#039;m Having issues with the MatchEvaluator in attribute strip.

********************
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1525: Invalid expression term &#039;&gt;&#039;

Source Error:

Line 76: 		MatchEvaluator HrefMatch = m =&gt; m.Groups[1].Value + &quot;href..;,;..&quot; + m.Groups[2].Value;

****************************
Any ideas?

Cheers,
Ben</description>
		<content:encoded><![CDATA[<p>Great procedure, thanks for developing.  I&#8217;m Having issues with the MatchEvaluator in attribute strip.</p>
<p>********************<br />
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.</p>
<p>Compiler Error Message: CS1525: Invalid expression term &#8216;&gt;&#8217;</p>
<p>Source Error:</p>
<p>Line 76: 		MatchEvaluator HrefMatch = m =&gt; m.Groups[1].Value + &#8220;href..;,;..&#8221; + m.Groups[2].Value;</p>
<p>****************************<br />
Any ideas?</p>
<p>Cheers,<br />
Ben</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mathias</title>
		<link>http://www.dijksterhuis.org/safely-cleaning-html-with-strip_tags-in-csharp/comment-page-1/#comment-595</link>
		<dc:creator>Mathias</dc:creator>
		<pubDate>Wed, 25 Mar 2009 10:59:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.dijksterhuis.org/?p=758#comment-595</guid>
		<description>Hi Martijn,

I found another problem: an attribute where the value contains &#039;-&#039; then only the part before &#039;-&#039; will be removed.

rgds,
Mathias</description>
		<content:encoded><![CDATA[<p>Hi Martijn,</p>
<p>I found another problem: an attribute where the value contains &#8216;-&#8217; then only the part before &#8216;-&#8217; will be removed.</p>
<p>rgds,<br />
Mathias</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mathias</title>
		<link>http://www.dijksterhuis.org/safely-cleaning-html-with-strip_tags-in-csharp/comment-page-1/#comment-588</link>
		<dc:creator>Mathias</dc:creator>
		<pubDate>Tue, 24 Mar 2009 17:12:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.dijksterhuis.org/?p=758#comment-588</guid>
		<description>Solved it quick and dirty

 string oldOutput;
            do
            {
                oldOutput = Output;
                /* Remove unsafe attributes in any of the remaining tags */
                Output = new Regex(@&quot;()&quot;).Replace(Output, UnsafeMatch);
            } while (oldOutput != Output);

rgds,
Mathias</description>
		<content:encoded><![CDATA[<p>Solved it quick and dirty</p>
<p> string oldOutput;<br />
            do<br />
            {<br />
                oldOutput = Output;<br />
                /* Remove unsafe attributes in any of the remaining tags */<br />
                Output = new Regex(@&#8221;()&#8221;).Replace(Output, UnsafeMatch);<br />
            } while (oldOutput != Output);</p>
<p>rgds,<br />
Mathias</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mathias</title>
		<link>http://www.dijksterhuis.org/safely-cleaning-html-with-strip_tags-in-csharp/comment-page-1/#comment-587</link>
		<dc:creator>Mathias</dc:creator>
		<pubDate>Tue, 24 Mar 2009 16:08:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.dijksterhuis.org/?p=758#comment-587</guid>
		<description>Hi Martijn,

Congrats for the nice post.

I have a problem when i have multipe attributes.  Only the last attribute is stripped.

code:
            string test = &quot;test paragraph&quot;;
            Console.WriteLine(StripTagsAndAttributes(test, new string[] { &quot;p&quot; }));

Rgds</description>
		<content:encoded><![CDATA[<p>Hi Martijn,</p>
<p>Congrats for the nice post.</p>
<p>I have a problem when i have multipe attributes.  Only the last attribute is stripped.</p>
<p>code:<br />
            string test = &#8220;test paragraph&#8221;;<br />
            Console.WriteLine(StripTagsAndAttributes(test, new string[] { &#8220;p&#8221; }));</p>
<p>Rgds</p>
]]></content:encoded>
	</item>
</channel>
</rss>
