<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Infovark Underground &#187; XML</title>
	<atom:link href="http://underground.infovark.com/category/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://underground.infovark.com</link>
	<description>The Infovark technology blog</description>
	<lastBuildDate>Tue, 06 Jul 2010 13:42:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Better ways to Encode HTML in C#</title>
		<link>http://underground.infovark.com/2009/12/11/better-ways-to-encode-html-in-c/</link>
		<comments>http://underground.infovark.com/2009/12/11/better-ways-to-encode-html-in-c/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 14:30:26 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[URI]]></category>

		<guid isPermaLink="false">http://underground.infovark.com/?p=547</guid>
		<description><![CDATA[Microsoft provides lots of different ways to encode HTML and URIs, but their newest library, called AntiXSS, is the best of the bunch.


Related posts:<ol><li><a href='http://underground.infovark.com/2009/02/18/using-wcf-to-return-html/' rel='bookmark' title='Permanent Link: Using WCF to return HTML'>Using WCF to return HTML</a></li>
<li><a href='http://underground.infovark.com/2009/01/14/jquery-turns-3/' rel='bookmark' title='Permanent Link: JQuery Turns 3'>JQuery Turns 3</a></li>
<li><a href='http://underground.infovark.com/2008/03/20/using-xmlconvert-for-datetime-strings/' rel='bookmark' title='Permanent Link: Using XmlConvert for DateTime Strings'>Using XmlConvert for DateTime Strings</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Our move from Windows Communication Foundation to C# WebServer once again raised the difficult question of <a href="http://en.wikipedia.org/wiki/HTML_encoding">HTML character encoding</a>. </p>
<p>Since we&#8217;re not using Microsoft IIS, we wanted to avoid a dependency on System.Web, which has the popular but flawed <code>HttpUtility.HtmlEncode()</code> method.</p>
<p>In my research, I discovered Rick Strahl&#8217;s post about <a href="http://www.west-wind.com/Weblog/posts/617930.aspx">Html and Uri String Encoding without System.Web</a>. He points out the problems and inconsistencies in the mainstream encoding methods available in the .NET framework, and ultimately decided to roll his own encoding method.</p>
<p>But in this StackOverflow question on <a href="http://stackoverflow.com/questions/1631819/htmlencode-in-c">HTML Encoding in C#</a>, several folks suggested using Microsoft&#8217;s <a href="http://en.wikipedia.org/wiki/Cross-site_scripting">anti-cross-site scripting</a> library, <a href="http://www.codeplex.com/AntiXSS">AntiXSS</a>.</p>
<p>After spending some time working with the library, it seems like just the thing to solve the problem of web encoding.</p>
<p>The AntiXSS Library includes helpful methods for encoding HTML, URLs, JavaScript, and XML. It&#8217;s based on a secure <a href="http://en.wiktionary.org/wiki/whitelist">whitelist</a> model, so anything not allowed in the specifications is prohibited. </p>
<p>Microsoft has made the source of AntiXSS 3.1 available on Codeplex (http://antixss.codeplex.com/), but you can also get the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=051ee83c-5ccf-48ed-8463-02f56a6bfc09&#038;displaylang=en">official release of AntiXSS</a> direct from Microsoft. It includes a sample application and thorough documentation. </p>
<p>It&#8217;s <em>exactly</em> the solution I was looking for. </p>


<p>Related posts:<ol><li><a href='http://underground.infovark.com/2009/02/18/using-wcf-to-return-html/' rel='bookmark' title='Permanent Link: Using WCF to return HTML'>Using WCF to return HTML</a></li>
<li><a href='http://underground.infovark.com/2009/01/14/jquery-turns-3/' rel='bookmark' title='Permanent Link: JQuery Turns 3'>JQuery Turns 3</a></li>
<li><a href='http://underground.infovark.com/2008/03/20/using-xmlconvert-for-datetime-strings/' rel='bookmark' title='Permanent Link: Using XmlConvert for DateTime Strings'>Using XmlConvert for DateTime Strings</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://underground.infovark.com/2009/12/11/better-ways-to-encode-html-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>One-Way Serialization</title>
		<link>http://underground.infovark.com/2008/10/05/one-way-serialization/</link>
		<comments>http://underground.infovark.com/2008/10/05/one-way-serialization/#comments</comments>
		<pubDate>Sun, 05 Oct 2008 15:31:13 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[serialization]]></category>

		<guid isPermaLink="false">http://underground.infovark.com/?p=110</guid>
		<description><![CDATA[Has anyone found a good pattern for serialization without deserialization? In my previous post about mixing serialization, I mentioned that we&#8217;d implemented the IXmlSerializable interface in many of our classes. The main reason for doing this was to include elements and attributes that were read-only. In other words, we wanted additional information to appear in [...]


Related posts:<ol><li><a href='http://underground.infovark.com/2008/09/17/dont-mix-your-serialization/' rel='bookmark' title='Permanent Link: Don&#8217;t Mix Your Serialization'>Don&#8217;t Mix Your Serialization</a></li>
<li><a href='http://underground.infovark.com/2009/05/14/validation-in-domain-driven-design/' rel='bookmark' title='Permanent Link: Validation in Domain Driven Design'>Validation in Domain Driven Design</a></li>
<li><a href='http://underground.infovark.com/2008/05/17/using-wcf-for-rest-part-2/' rel='bookmark' title='Permanent Link: Using WCF for REST, Part 2'>Using WCF for REST, Part 2</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Has anyone found a good pattern for serialization <em>without</em> deserialization?</p>
<p>In my previous post about <a href="http://underground.infovark.com/2008/09/17/dont-mix-your-serialization/">mixing serialization</a>, I mentioned that we&#8217;d implemented the <code>IXmlSerializable</code> interface in many of our classes. The main reason for doing this was to include elements and attributes that were read-only. </p>
<p>In other words, we wanted additional information to appear in the serialized stream. This additional information is not needed in order to rehydrate the object.</p>
<h4>Why would you want to do that?</h4>
<p>Most serialization frameworks don&#8217;t handle this case. After all, if the point of serialization is to transport an object across the wire, cluttering up the stream with extra information is wasteful. Besides, you can&#8217;t dictate what someone on the other side might do with the data. Nicholas Allen discusses this point in his post explaining why <a href="http://blogs.msdn.com/drnick/archive/2008/09/10/read-only-data-members.aspx">read-only data members are not supported in WCF</a>. </p>
<p>While I understand his point from an object remoting perspective, the reason for choosing XML as a data format in the first place was to allow for human readability. What if you want to embed metadata in your XML that doesn&#8217;t affect the behavior of the object? You&#8217;d need to include it in the XML output, but you aren&#8217;t interested reading it back in from an XML stream. What&#8217;s the best way to achieve this?</p>
<p>For example, in our data layer we have a Version object that brings together information about when the object was created and by whom, when it was modified and by whom, as well as the object&#8217;s revision number. It&#8217;s useful to have this information in resulting XML string, but we don&#8217;t need to read it back in.</p>
<p>So here&#8217;s my question: Are we doing this wrong? Does the need for one-way serialization indicate a problem with our object model? Is it a code smell, or is it simply an edge case not considered by existing frameworks?</p>


<p>Related posts:<ol><li><a href='http://underground.infovark.com/2008/09/17/dont-mix-your-serialization/' rel='bookmark' title='Permanent Link: Don&#8217;t Mix Your Serialization'>Don&#8217;t Mix Your Serialization</a></li>
<li><a href='http://underground.infovark.com/2009/05/14/validation-in-domain-driven-design/' rel='bookmark' title='Permanent Link: Validation in Domain Driven Design'>Validation in Domain Driven Design</a></li>
<li><a href='http://underground.infovark.com/2008/05/17/using-wcf-for-rest-part-2/' rel='bookmark' title='Permanent Link: Using WCF for REST, Part 2'>Using WCF for REST, Part 2</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://underground.infovark.com/2008/10/05/one-way-serialization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t Mix Your Serialization</title>
		<link>http://underground.infovark.com/2008/09/17/dont-mix-your-serialization/</link>
		<comments>http://underground.infovark.com/2008/09/17/dont-mix-your-serialization/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 21:33:38 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[JSON]]></category>

		<guid isPermaLink="false">http://underground.infovark.com/?p=112</guid>
		<description><![CDATA[Who doesn&#8217;t like mixing their Raisin Flakes with their Oaty-O&#8217;s in the morning? Yum! But it&#8217;s not a good idea if you&#8217;re talking about serial formats in C# 3.5 instead of breakfast cereals. You&#8217;ll get output that might leave a bad taste in your mouth. Breakfast Quiz Question: You&#8217;re writing a web API for an [...]


Related posts:<ol><li><a href='http://underground.infovark.com/2008/10/05/one-way-serialization/' rel='bookmark' title='Permanent Link: One-Way Serialization'>One-Way Serialization</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://underground.infovark.com/wp-content/uploads/2008/09/breakfast_time.jpg"><img src="http://underground.infovark.com/wp-content/uploads/2008/09/breakfast_time.jpg" alt="" title="breakfast_time" width="300" height="224" class="alignright size-full wp-image-125" /></a>Who doesn&#8217;t like mixing their Raisin Flakes with their Oaty-O&#8217;s in the morning? Yum! But it&#8217;s not a good idea if you&#8217;re talking about <em>serial</em> formats in C# 3.5 instead of breakfast cereals. You&#8217;ll get output that might leave a bad taste in your mouth.</p>
<h4>Breakfast Quiz</h4>
<p>Question: You&#8217;re writing a web API for an application. To give developers the most flexibility in interacting with your system, you want to expose classes that can be serialized to either XML or JSON. Using WCF and C# 3.5 SP1, what are your options?</p>
<p>Answer: There&#8217;s only one option unless you rely on 3rd party serialization libraries. You must mark the class with the <code>[DataContract]</code> attribute and mark each serializable member with <code>[DataMember]</code>. This allows you to serialize and deserialize using the <a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx">DataContractSerializer</a> and <a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx">DataContractJsonSerializer</a> for XML and JSON respectively.</p>
<p>I mention this because we&#8217;d gone to great lengths to customize our XML using the <a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.ixmlserializable.aspx">IXmlSerializable interface</a>. This gave us fine control over the properties we wanted to appear in our XML output and how they were formatted. But if you use the <code>IXmlSerializable</code> interface, you can&#8217;t also annotate the class with the <code>[DataContract]</code> attribute. You&#8217;ll get a compiler error. <a href="http://blogs.msdn.com/sowmy/archive/2006/05/14/597476.aspx">Sowmy Srinivasan explains this serialization restriction</a>.</p>
<p>I know what you&#8217;re thinking: If the framework provides an <code>IXmlSerializable</code> interface, isn&#8217;t there also an <code>IJsonSerializable</code> interface? Sadly, no. There&#8217;s no way to fine-tune the JSON output. Sigh.</p>
<p>So, if you&#8217;re currently using <code>IXmlSerializable</code>, you can forget about the <code>DataContractJsonSerializer</code>. Or you can accept that you&#8217;re <a href="http://underground.infovark.com/2008/05/06/fighting-the-framework/">fighting the framework</a>, forget about your fancy-pants XML format, and accept the default serialization, keeping these <a href="http://blogs.msdn.com/drnick/archive/2008/02/22/datamember-best-practices.aspx">data member best practices</a> in mind.</p>
<h4>What did we choose?</h4>
<p>Infovark has too much invested in our XML layout at this point. We&#8217;ve built our XSD files, XSL Transforms, and many, many unit tests. So we gave up on the <code>DataContractJsonSerializer</code> and turned to the excellent <a href="http://www.codeplex.com/Json">JSON.NET</a>, written by <a href="http://james.newtonking.com">James Newton-King</a>. It&#8217;s now version 3.0 and fully supports the new LINQ constructs.</p>
<p>It&#8217;s a little more work, but we think it&#8217;s worth it.</p>


<p>Related posts:<ol><li><a href='http://underground.infovark.com/2008/10/05/one-way-serialization/' rel='bookmark' title='Permanent Link: One-Way Serialization'>One-Way Serialization</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://underground.infovark.com/2008/09/17/dont-mix-your-serialization/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using XmlConvert for DateTime Strings</title>
		<link>http://underground.infovark.com/2008/03/20/using-xmlconvert-for-datetime-strings/</link>
		<comments>http://underground.infovark.com/2008/03/20/using-xmlconvert-for-datetime-strings/#comments</comments>
		<pubDate>Thu, 20 Mar 2008 15:09:34 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://underground.infovark.com/?p=4</guid>
		<description><![CDATA[James Newton-King, developer of the JSON.NET project, notes that it gets harder to be a .NET developer with every release. He reposted a chart from Brad Abrams showing the growth of the number of types in the Microsoft .NET framework. We&#8217;ve run into this problem all the time developing infovark. Often, it&#8217;s not the sheer [...]


Related posts:<ol><li><a href='http://underground.infovark.com/2008/09/02/converting-ienumerable-to-a-comma-delimited-string/' rel='bookmark' title='Permanent Link: Converting IEnumerable to a Comma-Delimited String'>Converting IEnumerable to a Comma-Delimited String</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>James Newton-King, developer of the JSON.NET project, notes that <a href="http://james.newtonking.com/archive/2008/03/19/being-a-microsoft-developer-getting-harder-every-year.aspx">it gets harder to be a .NET developer with every release</a>. He reposted <a href="http://blogs.msdn.com/brada/archive/2008/03/17/number-of-types-in-the-net-framework.aspx">a chart from Brad Abrams</a> showing the growth of the number of types in the Microsoft .NET framework.</p>
<p><a href="http://underground.infovark.com/?attachment_id=5" rel="attachment wp-att-5" title="More Types in Microsoft.NET Every Year"><img src="http://underground.infovark.com/wp-content/uploads/2008/03/dotnettypes.png" alt="More Types in Microsoft.NET Every Year" /></a></p>
<p>We&#8217;ve run into this problem all the time developing infovark. Often, it&#8217;s not the sheer size of the framework that proves challenging, but finding just the right method to do just the right thing.</p>
<p>A case in point was a recent problem I had in converting a <a href="http://msdn2.microsoft.com/en-us/library/system.datetime.aspx">DateTime</a> object into a string properly formatted for XML. Normally you&#8217;d do something like this:</p>
<p><code>string theDateString = myDateTime.ToString();</code></p>
<p>This gives you a string in the .NET format, but that&#8217;s not the correct format for XML Schema (XSD). No problem, you think, I&#8217;ll just pass a format argument to the ToString method. So you look up the available <a href="http://msdn2.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx">string formatting options</a> on MSDN. There&#8217;s lots of choices here, from the &#8220;based on ISO 8601&#8243; format to the &#8220;RFC1123Pattern&#8221; to the &#8220;UniversalSortableDateTimePattern&#8221;. But it turns out that <em>none</em> of these formats work for XML if you want it to validate against your XML Schema. What gives? Do you have to provide a custom formatting string to get the date pattern you want?</p>
<p>It turns out that you&#8217;re looking in the wrong place entirely. These aren&#8217;t the string formats you&#8217;re looking for. Move along.</p>
<p>What you want is in the System.Xml namespace. You want the <a href="http://msdn2.microsoft.com/en-us/library/system.xml.xmlconvert.aspx">XmlConvert</a> class. The XmlConvert class lets you convert from native .NET types to valid XML and back. The code looks like this:</p>
<p><code>string theDateString = XmlConvert.ToString(myDateTime);</code></p>
<p>It&#8217;s not only the size of the .NET framework that&#8217;s daunting. It&#8217;s the fact that functionality can be duplicated &#8212; or worse &#8212; made <em>just slightly different</em> across all of those classes. It puts developers in an awkward situation. Do they spend time researching to figure out exactly which method of which class in which namespace ought to be used in a given situation? Or do they roll their own (possibly buggy) implementation? It&#8217;s a tough call.</p>
<p>Personally, I&#8217;d like to see more guidance from Microsoft &#8212; perhaps through their code analysis tools &#8212; as to the preferred way of doing common tasks.</p>


<p>Related posts:<ol><li><a href='http://underground.infovark.com/2008/09/02/converting-ienumerable-to-a-comma-delimited-string/' rel='bookmark' title='Permanent Link: Converting IEnumerable to a Comma-Delimited String'>Converting IEnumerable to a Comma-Delimited String</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://underground.infovark.com/2008/03/20/using-xmlconvert-for-datetime-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
