<?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>Quickduck &#187; Xml</title> <atom:link href="http://quickduck.com/blog/category/development/xml/feed/" rel="self" type="application/rss+xml" /><link>http://quickduck.com/blog</link> <description>Straight from the mind of geniuseseses....</description> <lastBuildDate>Mon, 09 Jan 2012 02:29:30 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>MVC 3 XML Sitemap</title><link>http://quickduck.com/blog/2012/01/08/mvc-3-xml-sitemap/</link> <comments>http://quickduck.com/blog/2012/01/08/mvc-3-xml-sitemap/#comments</comments> <pubDate>Sun, 08 Jan 2012 01:24:36 +0000</pubDate> <dc:creator>Drew Freyling</dc:creator> <category><![CDATA[.Net]]></category> <category><![CDATA[Asp.Net]]></category> <category><![CDATA[Xml]]></category> <category><![CDATA[seo]]></category><guid isPermaLink="false">http://quickduck.com/blog/?p=425</guid> <description><![CDATA[Ok, so you&#8217;ve got your shiny new mvc3 app up and running. Now, it&#8217;s time to bake in some of that SEO goodness. Here&#8217;s how you can easily add a sitemap.xml to your new mvc application. The solution specified below not only pumps out the xml file to submit to the search engines, but it [...]]]></description> <content:encoded><![CDATA[<div class="google_plus_one"><g:plusone size="standard" count="false" url="http://quickduck.com/blog/2012/01/08/mvc-3-xml-sitemap/"></g:plusone></div><p>Ok, so you&#8217;ve got your shiny new mvc3 app up and running. Now, it&#8217;s time to bake in some of that SEO goodness. Here&#8217;s how you can easily add a sitemap.xml to your new mvc application. The solution specified below not only pumps out the xml file to submit to the search engines, but it is also a System.Web.SiteMapProvider, so you can use it for menus and wherever else you want to use your sitemap.</p><p>I&#8217;m a big fan of NuGet, so bring up the Package Manager Console and grab MvcSiteMapProvider (or download it from <a title="MvcSiteMapProvider" href="https://github.com/maartenba/MvcSiteMapProvider" target="_blank">github</a>).</p><pre class="brush: plain; title: ; notranslate">Install-Package MvcSiteMapProvider</pre><p>Once it is installed there will be a new Mvc.sitemap file added with the following to your solution:</p><pre class="brush: xml; title: ; notranslate">&lt;mvcSiteMapNode title=&quot;Home&quot; controller=&quot;Home&quot; action=&quot;Index&quot;&gt;
    &lt;mvcSiteMapNode title=&quot;About&quot; controller=&quot;Home&quot; action=&quot;About&quot;/&gt;
&lt;/mvcSiteMapNode&gt;</pre><p>Now for the easy bit: to get a ~/sitemap.xml to auto-generate for us based on our controller actions we specified in the sitemap file above. All you need to do is simply add the following to your route registration (generally Global.Application_Start()):</p><pre class="brush: csharp; title: ; notranslate">
XmlSiteMapController.RegisterRoutes(RouteTable.Routes);
</pre><p>Now, like a lot of other people out there my next question was, what about my dynamically generated content from the database (such as Product/Details/1)?  Easy &#8211; MvcSiteMapProvider comes with dynamic node support. Just create a class like the following:</p><pre class="brush: csharp; title: ; notranslate">

public class ProductDetailsDynamicNodeProvider : DynamicNodeProviderBase
 {
     public override IEnumerable&lt;DynamicNode&gt; GetDynamicNodeCollection()
     {
         // Create a node for each product
         foreach (Product product in productService.GetAllProducts())
         {
             var node = new DynamicNode();
             node.Title = product.Name;
             node.RouteValues.Add(&quot;id&quot;, product.Id);

             yield return node;
         }
     }
     public override CacheDescription GetCacheDescription()
     {
        return new CacheDescription(&quot;ProductDetailsDynamicNodeProvider&quot;)
        {
            SlidingExpiration = TimeSpan.FromMinutes(60);
        };
    }
 }
</pre><p>Things to note with the above code: you don&#8217;t have to override the cachedescription method, but this does allow us to specify how long all our products will be cached for in the sitemap. Then, you can add your dynamic node to the mvc.sitemap files as follows:</p><pre class="brush: xml; title: ; notranslate">
&lt;mvcSiteMapNode title=&quot;Details&quot; action=&quot;Details&quot;
dynamicNodeProvider=&quot;Website.ProductDetailsDynamicNodeProvider, Website&quot;/&gt;
</pre><p>Now you are done and have a working auto-generated mvc sitemap. For those of us who are using it to generate breadcrumbs, check out the awesome example of <a href="https://github.com/maartenba/MvcSiteMapProvider/wiki/HtmlHelper-functions" target="_blank">html helpers in the documentation</a>.</p><p>Next time, I&#8217;ll be looking at creating SEO friendly URLs in MVC.</p> ]]></content:encoded> <wfw:commentRss>http://quickduck.com/blog/2012/01/08/mvc-3-xml-sitemap/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>FirstObject XML Editor</title><link>http://quickduck.com/blog/2009/08/01/firstobject-xml-editor/</link> <comments>http://quickduck.com/blog/2009/08/01/firstobject-xml-editor/#comments</comments> <pubDate>Sat, 01 Aug 2009 13:00:02 +0000</pubDate> <dc:creator>Gerrod</dc:creator> <category><![CDATA[Applications]]></category> <category><![CDATA[Xml]]></category><guid isPermaLink="false">http://quickduck.com/blog/?p=128</guid> <description><![CDATA[I was looking for a fast, free XML editor today, which could handle fairly large (~100MB) XML files without too much hassle. Previously I&#8217;ve used XML Marker for this; it&#8217;s fantastic, however it has a fairly clunky interface. I wish SymbolClick would release a more modern version! Anyway, today I found FirstObject XML Editor and [...]]]></description> <content:encoded><![CDATA[<div class="google_plus_one"><g:plusone size="standard" count="false" url="http://quickduck.com/blog/2009/08/01/firstobject-xml-editor/"></g:plusone></div><p>I was looking for a fast, free XML editor today, which could handle fairly large (~100MB) XML files without too much hassle. <a href="http://quickduck.com/blog/2007/11/21/application-of-the-month/">Previously</a> I&#8217;ve used <a href="http://symbolclick.com/">XML Marker</a> for this; it&#8217;s fantastic, however it has a fairly clunky interface. I wish SymbolClick would release a more modern version!</p><p>Anyway, today I found <a href="http://www.firstobject.com/dn_editor.htm">FirstObject XML Editor</a> and gave it a try; so far it seems great! It&#8217;s lightweight (only a single EXE file), and it&#8217;s fast. Best of all, it has a very, very simple way to format (i.e. pretty print) XML files &#8211; just press F8!</p><p>Highly recommended.</p> ]]></content:encoded> <wfw:commentRss>http://quickduck.com/blog/2009/08/01/firstobject-xml-editor/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Persisting objects into database using xml serialization</title><link>http://quickduck.com/blog/2008/02/18/persisting-objects-into-database-using-xml-serialization/</link> <comments>http://quickduck.com/blog/2008/02/18/persisting-objects-into-database-using-xml-serialization/#comments</comments> <pubDate>Mon, 18 Feb 2008 11:56:00 +0000</pubDate> <dc:creator>Ben</dc:creator> <category><![CDATA[.Net]]></category> <category><![CDATA[Development]]></category> <category><![CDATA[Sql Server]]></category> <category><![CDATA[Xml]]></category><guid isPermaLink="false">http://quickduck.com/blog/2008/02/18/55/</guid> <description><![CDATA[Recently I showed you how to pull sql query result sets into object instances using the XmlReader and deserialization. This article aims to show you the opposite process &#8211; persisting an object instance into a database table using serialization and Sql Server xml parsing. The same Channel database table and entity class will be used [...]]]></description> <content:encoded><![CDATA[<div class="google_plus_one"><g:plusone size="standard" count="false" url="http://quickduck.com/blog/2008/02/18/persisting-objects-into-database-using-xml-serialization/"></g:plusone></div><p>Recently I <a href="http://quickduck.com/blog/2008/02/15/using-xmlreader-to-go-from-sql-result-set-to-a-list-of-objects/">showed</a> you how to pull sql query result sets into object instances using the XmlReader and deserialization. This article aims to show you the opposite process &#8211; persisting an object instance into a database table using serialization and Sql Server xml parsing.</p><p>The same Channel database table and entity class will be used for all examples.</p><p><img src='http://quickduck.com/blog/wp-content/uploads/2008/02/channeltable.JPG' alt='Channel Table Schema' /></p><pre class="brush: csharp; title: ; notranslate">/// Represents a media channel (e.g. web, mobile, iphone, etc.)
public class Channel
{
   public Channel()
   {
   }

   public Channel(string type, string description)
   {
       Type = type;
       Description = description;
   }

    /// Get/Set the channel identifier
    public int Id { get; set; }

    /// Get/Set the channel type (e.g. web, mobile, iphone, etc.)
    public string Type { get; set; }

    /// Get/Set the description of the channel.
    public string Description { get; set; }
 }</pre><h2>The Stored Procedure</h2><p>The sproc takes in an sql server xml datatype parameter. This is provided via a normal string representation of the xml. Within the SPROC you prepare the document for querying, pull out the values you require and perform the insert.</p><p>To understand the following SPROC, you need to have have a basic understanding of:</p><p><strong>a)</strong> how your object instance xml serialization format looks</p><pre><code>
&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;Channel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;Id>0&lt;/Id&gt;
  &lt;Type>web&lt;/Type&gt;
  &lt;Description>800x600 or larger browsers&lt;/Description&gt;
&lt;/Channel&gt;'
</code></pre><p>and</p><p><strong>b)</strong> an understanding of xpath and xquery for pulling the values out from the xml.</p><p>Check out the &#8211; <a href="http://quickduck.com/blog/sqlxml/">Resources &#8211; Sql Xml </a>- for some links that might help you out.</p><pre><code>
CREATE PROCEDURE [usp_PersistChannel]
	@xmldoc XML
AS
BEGIN
    SET NOCOUNT ON;

    DECLARE
            @iDoc int,
            @type varchar(50),
            @description varchar(255)

    EXEC sp_xml_preparedocument
           @iDoc OUTPUT,
           @xmldoc,
            '<Channel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />'

    SELECT
            @Type = [Type],
            @Description = [Description]
    FROM
            OPENXML (@iDoc, '/Channel',3)
	WITH (  [Type] varchar(50) './Type',
	Description] varchar(255) './Description' )

    EXEC sp_xml_removedocument @idoc

    INSERT INTO Channel VALUES (@Type, @Description)                

    SELECT @@IDENTITY
END
</code></pre><h2>Data Access Code</h2><p>The following is a convenience method to help aid the serialization process of an object instance.</p><pre><code>
        /// Serialize an instance of an object to a string.
        public string Serialize(object instance)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            XmlSerializer serializer = new XmlSerializer(instance.GetType(), null, new Type[0], null, null);
            serializer.Serialize(sw, instance);
            return sb.ToString();
        }
</code></pre><h2>Usage Examples:</h2><pre><code>

        /// Persist a Channel.
        public void Persist(Channel channel)
        {
            channel.Id = Int32.Parse(
                                Database.ExecuteScalar(
                                   Database.GetStoredProcCommand("usp_PersistChannel", Serialize(channel))
                                ).ToString()
                             );
        }
</code></pre>]]></content:encoded> <wfw:commentRss>http://quickduck.com/blog/2008/02/18/persisting-objects-into-database-using-xml-serialization/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: quickduck.com @ 2012-02-05 16:48:49 -->
