CSharp - XML Loading with XElement.Load()

Introduction

Loading into an element is virtually identical to loading into a document. Here are the methods available:

static XElement XElement.Load(string uri);
static XElement XElement.LoadTextReader textReader);
static XElement XElement.Load(XmlReader reader);
static XElement XElement.Load(string uri, LoadOptions options);
static XElement XElement.Load(TextReader textReader, LoadOptions options);
static XElement XElement.Load(XmlReader reader, LoadOptions options);

The following code contains an example loading the same XML file we saved with the XElement.Save method.

Demo

using System;
using System.Linq;
using System.Xml.Linq;
using System.Collections.Generic;

class Program/*from ww  w .  j av  a 2s  .c o m*/
{
    static void Main(string[] args){
        XElement xElement = XElement.Load("bookparticipants.xml");
        Console.WriteLine(xElement);
    }
}

Result

Related Topic