Training
Learning path
Access local files asynchronously - Training
Learn how to manage local files using the System.IO namespace and how to asynchronously back up and restore application data using the System.Text.Json namespace.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article shows how to load XML from a file in C# and Visual Basic using the XElement.Load method.
The following example shows how to load an XML document from a file by providing XElement.Load with the URI that references the file. The example loads books.xml and outputs the XML tree to the console.
The contents of books.xml are shown in Sample XML file: Books.
XElement booksFromFile = XElement.Load(@"books.xml");
Console.WriteLine(booksFromFile);
Dim booksFromFile As XElement = XElement.Load("books.xml")
Console.WriteLine(booksFromFile)
This example produces the following output:
<Catalog>
<Book id="bk101">
<Author>Garghentini, Davide</Author>
<Title>XML Developer's Guide</Title>
<Genre>Computer</Genre>
<Price>44.95</Price>
<PublishDate>2000-10-01</PublishDate>
<Description>An in-depth look at creating applications
with XML.</Description>
</Book>
<Book id="bk102">
<Author>Garcia, Debra</Author>
<Title>Midnight Rain</Title>
<Genre>Fantasy</Genre>
<Price>5.95</Price>
<PublishDate>2000-12-16</PublishDate>
<Description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</Description>
</Book>
</Catalog>
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Training
Learning path
Access local files asynchronously - Training
Learn how to manage local files using the System.IO namespace and how to asynchronously back up and restore application data using the System.Text.Json namespace.
Events
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in