I can not find an easy way to do what I’m asking for.
I have an object:
public class Item
{
public string Name { get; set; }
}
And i want to:
1) Create the xml document:
<?xml version="1.0" encoding="utf-8"?>
<Items>
<Item Name="Item1"/>
<Item Name="Item2"/>
</Items>
2) Read the xml document:
for each NodeT node in MyXMLDocument
{
Item i = new Item(node);
}
3) Manage the xml document, for example delete Item1 and add Item3 (or change attribute value)
<?xml version="1.0" encoding="utf-8"?>
<Items>
<Item Name="Item2"/>
<Item Name="Item3"/>
</Items>
How can I do this as simply as possible?
Thanks.
XML Serialization would be the easiest way in my view, although you have to sacrified
<items>for<ArrayOfItems>You can serialize your objects to a string, and then save them to a file:
Reading them back from XML to .NET objects just involves calling
Deserialize. You can also customise your objects using attributes if you need, allowing you to choose how they appear in the XML.