Updating xml with linq

In this post LINQ to XML Update Element Values, we shall see how to update the values of elements in an existing XML structure.

We will load an XML file from the disk, update the values of the elements and save the updated XML to the disk.

In many cases you can write the transformational code in a fraction of the time that it would take to manipulate the data store, and that code is more robust and easier to maintain.

In these cases, even though the transformational approach can take more processing power, it is a more effective way to modify data.

If you can take a representation of data and transform it efficiently from one form to another, the result is the same as if you took one data store and manipulated it in some way to take another shape.

A key to the functional construction approach is to pass the results of queries to XDocument and XElement constructors.

The functional approach yields code that is easier to maintain.

Notice that in this case the functional approach probably would not perform quite as well as the tree manipulation approach.

In contrast, when using the functional approach, you still just form the desired XML, embedding queries and expressions as appropriate, to pull in the desired content.

LINQ to XML enables another approach that is useful in many scenarios: .

Functional construction treats modifying data as a problem of transformation, rather than as detailed manipulation of a data store.

Serialization/Deserialization is a cool and important feature of an application.

It is required when your want to communicate/send data to other applications.

Search for updating xml with linq:

updating xml with linq-67updating xml with linq-22updating xml with linq-45updating xml with linq-68

If a developer is familiar with the functional approach, the resulting code in many cases is easier to understand.

Leave a Reply

Your email address will not be published. Required fields are marked *

One thought on “updating xml with linq”