---
title: "How add value on xml in specified node"  
description: "How add value on xml in specified node"  
author: "Royce Roy"  
published: 2014-01-27  
updated: 2014-01-27  
canonical: https://www.mindstick.com/forum/1882/how-add-value-on-xml-in-specified-node  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How add value on xml in specified node

I need write [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) on c#, which [check](https://yourviews.mindstick.com/story/2248/never-forget-to-check-these-specifications-before-buying-a-mobile-phone), if exist [node](https://www.mindstick.com/forum/161418/what-is-node-js-and-how-does-it-work) on [xml](https://www.mindstick.com/blog/203/working-with-xml-data-in-sql-server). If not: [insert](https://www.mindstick.com/blog/173/executing-insert-delete-or-update-query-in-sqlserver-using-ado-dot-net) [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages). So I have tree [path](https://www.mindstick.com/articles/44333/4-expert-tips-on-how-to-pick-the-right-career-path): ./a/d and some line, which I need insert:

<e [name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide)="aaa" value="bbb" />

How read and insert value in correct place? This is original xml:

```
 <?xml version="1.0" encoding="utf-8"?>    <a>      <b>     
<c></c>      </b>    </a>
```

After , I need XML:

```
<?xml version="1.0" encoding="utf-8"?>    <a>      <b>     
<c></c>      </b>      <d>        <e name="aaa" value="bbb" />      </d>    </a>
```

So, can you help me with [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii)?

## Replies

### Reply by Pravesh Singh

Hi Royce,\

It's easy with LINQ to XML

```
var xDoc = XElement.Load("path");var elemens =xDoc.Elements("a").First().Element("b");element.AddAfterSelf(new XElement("d",                           
new XElement("e", newXAttribute("name","aaa"),                                            
new XAttribute("value","bbb"))));xDoc.Save("path");
```


---

Original Source: https://www.mindstick.com/forum/1882/how-add-value-on-xml-in-specified-node

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
