XML
Back to TOCCondensed TOC
Extensible Markup Language
- Comparing LINQ to XML and XPath
- A More Robust Approach for Handling XName Objects in LINQ to XML
- Writing Succinct Code to move XElement and XAttribute Objects from One LINQ to XML Tree to Another
- Equality Semantics of LINQ to XML Trees
- Manually Cloning LINQ to XML Trees
- Querying LINQ to XML Nodes in Reverse Document Order with Better Performance
- Document-Centric Transforms using LINQ to XML
- Recursive Approach to Pure Functional Transformations of XML
- Implementing ‘Inheritance’ in XML
- Align Attributes when Formatting XML using LINQ to XML
- Writing Entity References using LINQ to XML
- Convert XDocument to XmlDocument (and Convert XmlDocument to XDocument)
- Serializing Encoded XML Documents using LINQ to XML
- Controlling Namespace Serialization of LINQ to XML
- XML Element and Attribute Name Guidelines
- Working with Optional Elements and Attributes in LINQ to XML Queries
- Custom Formatting of XML using LINQ to XML
Provides an overview of the similarities and differences between XPath and LINQ to XML (Article)
Pre-atomizing XName objects enables you to write more reliable code that performs well. (Article)
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. (Article)
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. (Article)
There are a variety of circumstances where you want to clone a LINQ to XML tree while making modifications to the cloned tree. It’s possible to write a very small amount of recursive code to do this. (Article)
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. (Article)
When thought of in a certain way, XML documents come in two flavors – 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 – data-centric to document-centric, document-centric to data-centric, and document-centric to document-centric. (Article)
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. (Article)
Some XML vocabularies implement a powerful XML pattern that is analogous to inheritance in programming language type systems. Open XML WordprocessingML has these semantics around styles. When you define a new style, you can base this style on another style, and if the new style doesn’t explicitly define some aspect of the style, the new style ‘inherits’ this aspect from its base style. This post presents some code that uses one approach for implementing inheritance semantics. (Article)
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. (Article)
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. (Article)
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’t good enough – you need to convert from an XDocument to XmlDocument and back. (Article)
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. (Article)
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. (Article)
Some time ago, a dev team here at Microsoft asked me to review their XML vocabulary that they had designed. They wanted to know if the element and attribute names in their vocabulary design were good ones. This is the advice that I gave them. (Article)
Keywords: XML
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. (Article)
Demonstrates the ability to customize the serialization of XML trees when using LINQ to XML. (Article)