7.2. Load an XML File into Memory

Problem

You need to load the contents of an XML file into memory.

Solution

Use the Load method of the XElement or XDocument class.

How It Works

Recipe 7-1 covered XElement, the primary LINQ to XML class for working with XML trees. Although this class is extremely powerful, it does not provide properties or methods for working with all aspects of a full XML document, such as comments or processing instructions. To work with this extended information, you must rely on the XDocument class.

Although the XElement class can contain any number of child elements, the XDocument class, which represents the very top level of an XML document itself, can have only one child element. This one element, accessed by the Root ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.