Note that there are some explanatory texts on larger screens.

plurals
  1. POSerialized, Deserialized, Append, Get, Delete Object in XML file C#
    primarykey
    data
    text
    <p>I have the following class</p> <pre><code>[Serializable] public class Product { public Product() { } public string ProductID { get; set; } public string Name { get; set; } public string Description { get; set; } } </code></pre> <p>I want to create a XML file from object. if the product id exist, update the node other wise add or append the node in xml file.</p> <p>i am using the following code to serialize object </p> <pre><code>public void SerializeNode(object obj, string filepath) { XmlSerializer serializer = new XmlSerializer(obj.GetType()); var writer = new StreamWriter(filepath); serializer.Serialize(writer.BaseStream, obj); } </code></pre> <p>but it create the file every time from scratch so if the data exist in the file it overwites it with new one.</p> <p>so i am in search of mechanism where it add/append node in xml, get the node based on ProductID and delete the node. </p> <p>The class can be extended with more data members so the code should be dynamic so i don't have to specify child elements in code, i want it only in class level.</p> <p>hope some one can help </p> <p>the structure i am looking for is as follow</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Products&gt; &lt;Product ProductID="1"&gt; &lt;Name&gt;Product Name&lt;/Name&gt; &lt;Description&gt;Product Description&lt;/Description&gt; &lt;/Product&gt; &lt;Product ProductID="2"&gt; &lt;Name&gt;Product Name&lt;/Name&gt; &lt;Description&gt;Product Description&lt;/Description&gt; &lt;/Product&gt; &lt;Product ProductID="3"&gt; &lt;Name&gt;Product Name&lt;/Name&gt; &lt;Description&gt;Product Description&lt;/Description&gt; &lt;/Product&gt; &lt;/Products&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload