Note that there are some explanatory texts on larger screens.

plurals
  1. POXML serialize without overwriting
    primarykey
    data
    text
    <p>How can I serialize data to xml without overwriting previous data? In this code I am able to make XML file but when I run this again I overwrite what I saved previously:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Xml.Serialization; namespace ActorGenerator { class Program { static void Main() { Console.Write("How many actors you want to add? "); int max = 0; max = int.Parse(Console.ReadLine()); for (int i = 0; i &lt; max; i++) { int x = i + 1; Console.WriteLine("////////////////////////ACTOR" + x + "/////////////////////////////////"); Actor actor1 = new Actor(); Console.Write("NAME (string): "); actor1.Name = Console.ReadLine(); Console.Write("AGE (int): "); actor1.Age = int.Parse(Console.ReadLine()); Console.Write("FOCUS (string): "); actor1.Focus = Console.ReadLine(); Console.Write("PRICE (int): "); actor1.Price = int.Parse(Console.ReadLine()); Console.Write("CONTRACTED (true/false): "); actor1.Contracted = bool.Parse(Console.ReadLine()); Console.Write("PLAYING IN FILM (true/false): "); actor1.PlayingInFilm = bool.Parse(Console.ReadLine()); Console.Write("SKILL (int): "); actor1.Skill = int.Parse(Console.ReadLine()); SerializeToXML(actor1); } } static public void SerializeToXML(Actor actor) { XmlSerializer serializer = new XmlSerializer(typeof(Actor)); TextWriter textWriter = new StreamWriter(@"c:\users\Desktop\actor.xml"); serializer.Serialize(textWriter, actor); textWriter.Close(); } } public class Actor { public string Name { get; set; } public int Age { get; set; } public string Focus { get; set; } public int Price { get; set; } public bool Contracted { get; set; } public bool PlayingInFilm { get; set; } public int Skill { get; set; } } } </code></pre> <p>Also, how can I read XML data and store it into variable?</p>
    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.
    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