C#, XML, and LINQ: Load & Parse an XML File
I promised an example of using LINQ and C# together before the month was out, and it here it is! Whoo. Go me.
xml
I promised an example of using LINQ and C# together before the month was out, and it here it is! Whoo. Go me.
My previous example only covered loading and parsing an XML document. This example will include the code I used to add new nodes to the XML tree.
So far, I have shown you how to load and parse an XML document into a C# class, and also how to add new nodes to an XML document using C#. So now we have reached the fun part: updating an existing node!
So far we've learned how to load & parse an XML file, add new nodes to it, and update it's nodes. Today we're gonna learn the scary part: deleting nodes.
I've had a sitemap for this site for quite a while. Google (and the various other search engines) loves them some sitemaps, since it helps them crawl your site a little faster and more efficiently. For those of you wondering what a sitemap is, it is a XML document that contains an element for every public-facing page in your web site. A good sitemap follows the standard setup by Sitemaps.org, a collaboration between Google, Yahoo, and Microsoft to establish a standard sitemap format. You can deviate from the sitemap protocol if you're feeling rebellious, but the search engines will respond by ignoring your sitemap (and perhaps your site in the process).
I was working on my capstone project last semester, and ran into a need to log exception data to a portable format. I loves me some XML, so that was my obvious (and, let's be honest, only) choice. .NET includes a lot of built-in code in most data types to allow for seamless serialization, so I thought this would be a simple matter.