Namespaces and the XmlDataSource Server Control

Scott Hanselman discussed this earlier, but the XmlDataSource control has a bug in it. When working with the XPath capablities of the control (which you will do pretty much every time you use the control), the control will throw an exception when working with XML data that includes namespaces/prefixes. I recently encountered this problem when I was working with some of the XML data coming from the Amazon APIs.

One possible fix is to apply a XSLT stylesheet to strip the namespaces and prefixes from the XML. The XSL doc you would use would look as follows:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
   <xsl:template match="*">
      <!-- Remove any prefixes -->
      <xsl:element name="{local-name()}">
          <!-- Work through attributes -->
          <xsl:for-each select="@*">
             <!-- Remove any attribute prefixes -->
             <xsl:attribute name="{local-name()}">
                <xsl:value-of select="."/>
             </xsl:attribute>
          </xsl:for-each>
      <xsl:apply-templates/>
      </xsl:element>
   </xsl:template>
</xsl:stylesheet>

Then with the XSL doc in place, you can then use the XmlDataSource control to make use of this document:

<asp:XmlDataSource ID="XmlDataSource1" runat="server"
 DataFile="NamespaceFilled.xml" TransformFile="~/RemoveNamespace.xsl"
 XPath="ItemLookupResponse/Items/Item"></asp:XmlDataSource>
«October»
SunMonTueWedThuFriSat
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345