{"id":696,"date":"2011-12-01T04:06:51","date_gmt":"2011-12-01T04:06:51","guid":{"rendered":"http:\/\/www.ericwhite.com\/home2\/bm8qcmjy\/public_html\/blog\/?page_id=696"},"modified":"2014-03-04T05:57:40","modified_gmt":"2014-03-04T05:57:40","slug":"linq-to-xml-expanded","status":"publish","type":"page","link":"https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded\/","title":{"rendered":"LINQ to XML"},"content":{"rendered":"<h2 style='font-size: small;'><a href='https:\/\/www.ericwhite.com\/blog\/toc-expanded'>Back to TOC<\/a><a style='position: relative; left: 1em;' href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-video-expanded'>Just Videos<\/a><span style='position: relative; left: 2em;'><a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-condensed'>Condensed TOC<\/a><\/span><\/h2>\n<p>Access XML documents using Language Integrated Query (LINQ)<\/p>\n<ul>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2007\/12\/06\/performance-of-chained-queries.aspx\" target=\"_blank\">Performance of Chained Queries<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>One of the most important aspects of LINQ (and LINQ to XML) is that performance of chained queries can be effectively the same as if you write one larger, more complicated query.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2007\/12\/06\/atomized-xname-and-xnamespace-objects.aspx\" target=\"_blank\">Atomized XName and XNamespace Objects<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>XName and XNamespace objects are atomized. This yields performance benefits for queries: comparing two atomized names for equality means that the underlying intermediate language (IL) only needs to determine if the two references point to the same object. The underlying system does not need to do any string comparisons, which would be time consuming.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2007\/12\/06\/preatomization-of-xname-objects.aspx\" target=\"_blank\">Preatomization of XName Objects<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>One approach that you can take to gain some performance is to pre-atomize XName objects. This would yield performance benefits when creating a large XML tree where specific names are repeated. The approach is to declare and initialize XName objects before the construction of the XML tree, and then to use the XName objects rather than specifying strings for the element and attribute names.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2007\/12\/06\/statically-compiled-queries.aspx\" target=\"_blank\">Statically Compiled Queries<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>One of the most important performance benefits that you will note when comparing LINQ to XML and XmlDocument is that queries in LINQ to XML are statically compiled, whereas XPath queries must be interpreted at runtime.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2007\/12\/06\/performance-of-linq-to-xml.aspx\" target=\"_blank\">Performance of LINQ to XML<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>There are a number of issues and dynamics that we can talk about with regards to performance of LINQ to XML. <span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/07\/14\/writing-robust-linq-to-xml-code-that-performs-well.aspx\" target=\"_blank\">Writing Robust LINQ to XML Code that Performs Well<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Lists some important posts about LINQ to XML that explains approaches that you can take to write LINQ to XML code that has fewer bugs.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/07\/23\/removing-comments-and-personal-information-and-accepting-revisions-in-an-open-xml-document-stored-in-sharepoint.aspx\" target=\"_blank\">Removing Comments and Personal Information, and Accepting Revisions in an Open XML Document Stored in SharePoint<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>This post presents a custom application page in SharePoint that uses Open XML, the Open XML SDK and LINQ to XML to accept revisions, remove comments, and remove personal information from an Open XML word processing document.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/openxml-expanded'>OpenXML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/sharepoint-2010-expanded'>SharePoint 2010<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/wordprocessingml-expanded'>WordprocessingML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/08\/03\/linq-reduces-line-counts-and-makes-code-pop.aspx\" target=\"_blank\">Generating a LINQ to XML Tree from Anonymous Types<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Shows how to write code to generate an XML tree from a hierarchy of anonymous types.  In addition, it compares and contrasts writing code in the imperative style to writing code in the declarative style.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/10\/12\/using-linq-to-xml-events-and-annotations-to-track-if-an-xml-tree-has-changed.aspx\" target=\"_blank\">Using LINQ to XML Events and Annotations to Track if an XML Tree has Changed<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>You may optionally be making a number of modifications to a very large XDocument object.  Because of a complicated algorithm, you may not necessarily know ahead of time whether you will be making changes.  If you don&#8217;t make any changes, then you don&#8217;t want to unnecessarily serialize the tree and save it to disk, or send it over the wire.  This post presents a simple technique to determine if an XDocument has ever been modified since deserialization or creation.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/10\/24\/comparing-linq-to-xml-and-xpath.aspx\" target=\"_blank\">Comparing LINQ to XML and XPath<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Provides an overview of the similarities and differences between XPath and LINQ to XML<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/xml-expanded'>XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/12\/15\/a-more-robust-approach-for-handling-xname-objects-in-linq-to-xml.aspx\" target=\"_blank\">A More Robust Approach for Handling XName Objects in LINQ to XML<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Pre-atomizing XName objects enables you to write more reliable code that performs well.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/openxml-expanded'>OpenXML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/open-xml-sdk-expanded'>Open XML SDK<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/xml-expanded'>XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2009\/01\/01\/writing-succinct-code-to-move-xelement-and-xattribute-objects-from-one-linq-to-xml-tree-from-another.aspx\" target=\"_blank\">Writing Succinct Code to move XElement and XAttribute Objects from One LINQ to XML Tree to Another<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>This post presents an interesting idiom of LINQ to XML that makes it easy to write short, succinct code when creating one XML tree from another.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/openxml-expanded'>OpenXML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/xml-expanded'>XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2009\/01\/04\/getting-started-with-sharepoint-wss-web-services-using-linq-to-xml.aspx\" target=\"_blank\">Getting Started with SharePoint Web Services using LINQ to XML<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Web services are one of the most effective and convenient ways for casual developers to access SharePoint lists and document libraries.  They have a reputation for being a bit difficult;  LINQ to XML can make them easier to use.  This post presents the basic steps for getting started with Windows SharePoint Services Web Services using LINQ to XML (either C# or VB).<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/sharepoint-2010-expanded'>SharePoint 2010<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/web-services-expanded'>Web Services<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2009\/01\/28\/equality-semantics-of-linq-to-xml-trees.aspx\" target=\"_blank\">Equality Semantics of LINQ to XML Trees<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>In certain scenarios, it is important to be able to compare two XML trees for equivalence.  For example, if you are writing a web service that serves results of queries, and you want to cache query results so that duplicate queries use previously cached results instead of always accessing the underlying database.  However, the senders of those queries may potentially be using a variety of tools to generate the queries, and these tools may introduce trivial differences into the XML.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/xml-expanded'>XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2009\/01\/28\/manually-cloning-linq-to-xml-trees.aspx\" target=\"_blank\">Manually Cloning LINQ to XML Trees<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>There are a variety of circumstances where you want to clone a LINQ to XML tree while making modifications to the cloned tree.  It&#8217;s possible to write a very small amount of recursive code to do this.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/xml-expanded'>XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2009\/02\/18\/the-composability-thought-process-for-linq.aspx\" target=\"_blank\">The Composability Thought Process for LINQ<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>This post demonstrates the thought process of developing a somewhat more involved query.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/openxml-expanded'>OpenXML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2009\/02\/20\/ease-of-maintenance-of-linq-code.aspx\" target=\"_blank\">Ease of Maintenance of LINQ Code<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>I believe that it is easier to maintain code that is written in the functional style.  For one thing, this is the very reason for many of the characteristics of functional code.  No state is maintained, so we don&#8217;t have to worry about corrupting any state.  If a variable is in scope, then the variable has its value, and it will never have another value.  And the idea of composability is all about being able to inject\/surround\/refactor code without making it brittle.  In this post, I&#8217;m going to show the process of maintaining and modifying a somewhat more involved query.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/openxml-expanded'>OpenXML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2009\/02\/21\/computing-deep-hash-codes-using-linq-to-xml.aspx\" target=\"_blank\">Computing Deep Hash Codes using LINQ to XML<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>In some scenarios, it is useful to compute a &#8216;deep&#8217; hash code using LINQ to XML.  If you are writing a server-side application that caches queries expressed in XML, then you may want to store these queries in a hash table.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2009\/02\/22\/ease-of-maintenance-of-linq-code-2.aspx\" target=\"_blank\">Ease of Maintenance of LINQ Code (2)<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>In two previous posts, I developed a somewhat involved query to search through a word processing document for style names and\/or paragraph content.  This is a query that I&#8217;m developing for the PowerTools for Open XML project.  In those posts, as I evolved the query, I showed each iteration of it, highlighting the changes I made.  This post continues modifying that query.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/openxml-expanded'>OpenXML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2009\/06\/24\/querying-linq-to-xml-nodes-in-reverse-document-order-with-better-performance.aspx\" target=\"_blank\">Querying LINQ to XML Nodes in Reverse Document Order with Better Performance<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Occasionally I need to query LINQ to XML nodes in reverse document order.  However, nodes in LINQ to XML are forward-linked only, so getting the previous sibling element can perform slowly.  This post presents an approach for significant performance gains.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/xml-expanded'>XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2009\/07\/09\/document-centric-transforms-using-linq-to-xml.aspx\" target=\"_blank\">Document-Centric Transforms using LINQ to XML<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>When thought of in a certain way, XML documents come in two flavors &#8211; data-centric and document-centric.  Further, there are two types of document-centric documents.  This post presents my thoughts about approaches to various types of document-centric transformations &#8211; data-centric to document-centric, document-centric to data-centric, and document-centric to document-centric.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/xml-expanded'>XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2009\/07\/20\/a-tutorial-in-the-recursive-approach-to-pure-functional-transformations-of-xml.aspx\" target=\"_blank\">Recursive Approach to Pure Functional Transformations of XML<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Writing pure functional transformations a in a recursive style enables us to put together interesting transformations in a very small amount of code.  Using some specific techniques that allow us to write this code very concisely, this approach takes advantage of some perhaps obscure semantics of LINQ to XML.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/xml-expanded'>XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2008\/12\/30\/align-attributes-when-formatting-xml-using-linq-to-xml.aspx\" target=\"_blank\">Align Attributes when Formatting XML using LINQ to XML<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Sometimes an XML element contains a large number of attributes, and the values of the attributes may be long.  When written to the console, such lines wrap, making it hard to read the XML.  This post shows how you can use appropriate settings for an XmlWriter so that the attributes are aligned, and each attribute is on a separate line.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/openxml-expanded'>OpenXML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/xml-expanded'>XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2010\/01\/21\/writing-entity-references-using-linq-to-xml.aspx\" target=\"_blank\">Writing Entity References using LINQ to XML<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>As delivered, it is difficult to write entities using LINQ to XML.  This post presents a small hack that enables you to serialize XML entities.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/openxml-expanded'>OpenXML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/open-xml-sdk-expanded'>Open XML SDK<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/wordprocessingml-expanded'>WordprocessingML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/powertools-for-open-xml-expanded'>PowerTools for Open XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/xml-expanded'>XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2010\/03\/05\/convert-xdocument-to-xmldocument-and-convert-xmldocument-to-xdocument.aspx\" target=\"_blank\">Convert XDocument to XmlDocument (and Convert XmlDocument to XDocument)<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Some time ago, I blogged about an approach for converting an XElement object to an XmlNode object, and vice versa.  This is useful when you want to use a programming interface that takes and returns objects of type XmlNode, but you want to use the expressiveness and power of LINQ to XML for your code that modifies the XML tree.  There are a few occasions where this isn&#8217;t good enough &#8211; you need to convert from an XDocument to XmlDocument and back.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/xml-expanded'>XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2010\/03\/08\/serializing-encoded-xml-documents-using-linq-to-xml.aspx\" target=\"_blank\">Serializing Encoded XML Documents using LINQ to XML<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Writing encoded (utf-8, utf-16, etc.) documents using LINQ to XML is pretty straight-forward, but there is one interesting dynamic of the semantics.  When serializing to a file on disk, then you can set the encoding in the XML declaration, and the resulting XML document will be serialized as you wish.  However, if you are writing to a stream that supports only one specific encoding, then the XML document will automatically be encoded to match the stream, overriding your specified desired encoding, and the XML declaration will be adjusted accordingly.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/xml-expanded'>XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2010\/04\/16\/controlling-namespace-serialization-of-linq-to-xml.aspx\" target=\"_blank\">Controlling Namespace Serialization of LINQ to XML<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>You can explicitly control how LINQ to XML serializes the namespaces for an XML tree.  You can control whether a namespace is serialized as the default namespace for a tree, or whether the namespace will use a prefix.  <span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/xml-expanded'>XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class='ericListItem' href='https:\/\/www.ericwhite.com\/blog\/2011\/02\/11\/simulating-virtual-extension-methods\/' target='_blank'>Simulating Virtual Extension Methods<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Similating virtual extension methods can help in solving problems when dealing with a class hierarchy that uses polymorphism.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class='ericListItem' href='https:\/\/www.ericwhite.com\/blog\/2011\/02\/18\/refinement-generating-c-code-from-an-xml-tree-using-virtual-extension-methods\/' target='_blank'>Refinement: Generating C# code from an XML Tree using Virtual Extension Methods<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Discusses code that can generate C# code to generate any arbitrary XML tree.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class=\"ericListItem broken_link\" href=\"http:\/\/blogs.msdn.com\/b\/ericwhite\/archive\/2009\/05\/14\/working-with-optional-elements-and-attributes-in-linq-to-xml-queries.aspx\" target=\"_blank\">Working with Optional Elements and Attributes in LINQ to XML Queries<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Often XML schemas allow for optional elements and attributes.  When you write queries on these elements or attributes, you may be tempted to write code that does lots of testing for null.  There is a better way to do this, laid out in this post.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/xml-expanded'>XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class='ericListItem' href='https:\/\/www.ericwhite.com\/blog\/2011\/04\/08\/review-of-xpath-semantics-of-linq-to-xml\/' target='_blank'>Review of XPath Semantics of LINQ to XML<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>In this post, I review the XPath semantics of LINQ to XML, and show some concrete examples of how I use those semantics in the XPath-in-Content-Controls approach to Open XML WordprocessingML document generation.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/openxml-expanded'>OpenXML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/docx-generation-expanded'>DOCX Generation<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/wordprocessingml-expanded'>WordprocessingML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class='ericListItem' href='https:\/\/www.ericwhite.com\/blog\/2011\/05\/09\/custom-formatting-of-xml-using-linq-to-xml-2\/' target='_blank'>Custom Formatting of XML using LINQ to XML<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>Demonstrates the ability to customize the serialization of XML trees when using LINQ to XML.<span style='color:#2b91af;'>  (Article)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/xml-expanded'>XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<li class='ericListItem'><a class='ericListItem' href='http:\/\/openxmldeveloper.org\/home2\/bm8qcmjy\/public_html\/blog\/b\/openxmldeveloper\/archive\/2011\/11\/16\/screen-cast-functional-programming-utility-methods-and-classes-for-open-xml.aspx' target='_blank'>Screen-Cast: Functional Programming Utility Methods and Classes for Open XML<\/a><\/li>\n<p><\/p>\n<div style='margin-left: 2em; margin-bottom: 1em;'>In the process of developing the PowerTools for Open XML, over the years, I have developed some needed core functionality and utility methods, particularly for writing LINQ to XML code that queries and transforms Open XML documents.<span style='color:#2b91af;'>  (Video)<\/span><\/p>\n<div style='vertical-align: text-top; margin-top: .5em;'><span style='color:#2b91af;'>Keywords:&nbsp;&nbsp;<\/span><a href='https:\/\/www.ericwhite.com\/blog\/openxml-expanded'>OpenXML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/powertools-for-open-xml-expanded'>PowerTools for Open XML<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/functional-programming-expanded'>Functional Programming<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-expanded'>LINQ<\/a>&nbsp;&nbsp;<a href='https:\/\/www.ericwhite.com\/blog\/linq-to-xml-expanded'>LINQ to XML<\/a>&nbsp;&nbsp;<\/div>\n<\/div>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Back to TOCJust VideosCondensed TOC Access XML documents using Language Integrated Query (LINQ) Performance of Chained Queries One of the most important aspects of LINQ (and LINQ to XML) is that performance of chained queries can be effectively the same as if you write one larger, more complicated query. (Article) Keywords:&nbsp;&nbsp;Functional Programming&nbsp;&nbsp;LINQ to XML&nbsp;&nbsp; Atomized [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"_s2mail":"","footnotes":""},"class_list":["post-696","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/pages\/696","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/comments?post=696"}],"version-history":[{"count":7,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/pages\/696\/revisions"}],"predecessor-version":[{"id":8033,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/pages\/696\/revisions\/8033"}],"wp:attachment":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/media?parent=696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}