---
title: "How to parsing XML and extracting nodes?"  
description: "How to parsing XML and extracting nodes?"  
author: "Jayden Bell"  
published: 2015-01-27  
updated: 2015-01-27  
canonical: https://www.mindstick.com/forum/12907/how-to-parsing-xml-and-extracting-nodes  
category: "asp.net"  
tags: ["c#", "xml", "xml parsing"]  
reading_time: 1 minute  

---

# How to parsing XML and extracting nodes?

I have the following [XML](https://www.mindstick.com/blog/203/working-with-xml-data-in-sql-server):

```
<bookstore>    <book genre='autobiography' publicationdate='1981-03-22' ISBN='1-861003-11-0'>        <title>The Autobiography of Benjamin Franklin</title>        <author>            <first-name>Benjamin</first-name>            <last-name>Franklin</last-name>        </author>        <price>8.99</price>    </book></bookstore>
```

**I want to read it and display the [result](https://www.mindstick.com/blog/12011/advantages-of-getting-result-oriented-seo-from-an-agency) as following:**

Genre: autobiography

Publication: 1981-03-22

ISBN: 1-861003-11-0

[Title](https://www.mindstick.com/articles/12860/how-to-get-financing-for-salvage-title-cars): The Autobiography of [Benjamin Franklin](https://answers.mindstick.com/qa/41936/what-new-delivery-system-did-benjamin-franklin-introduce)

Author: Benjamin Franklin

Price: 8.99

## Replies

### Reply by Takeshi Okada

Here you have some example code to do this with XElement:

```
 var xml = XElement.Load("test.xml");     foreach (var bookEl in xml.Elements("book"))    {        Console.WriteLine("Genre:" + bookEl.Attribute("genre").Value            + "" + "Publication: " + bookEl.Attribute("publicationdate").Value            + "" + "ISBN: " + bookEl.Attribute("ISBN").Value);        Console.WriteLine("Title:" + bookEl.Element("title").Value);        Console.WriteLine("Author:" + bookEl.Element("author").Element("first-name").Value
            + "
" + bookEl.Element("author").Element("last-name").Value);        Console.WriteLine("Price:" + bookEl.Element("price").Value);    }
```


---

Original Source: https://www.mindstick.com/forum/12907/how-to-parsing-xml-and-extracting-nodes

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
