Created
June 11, 2015 18:58
-
-
Save jacks205/b02086405d5f6bbb48d8 to your computer and use it in GitHub Desktop.
Write to XML File C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Xml.Serialization; | |
namespace JanteqTestConsoleApplication | |
{ | |
public class Program | |
{ | |
static void Main(string[] args) | |
{ | |
WriteXML(); | |
} | |
public class Book | |
{ | |
public String title; | |
public Author author; | |
public void Read() | |
{ | |
} | |
} | |
public class Author | |
{ | |
public String name; | |
} | |
public static void WriteXML() | |
{ | |
Book overview = new Book(); | |
overview.title = "Serialization Overview"; | |
overview.author = new Author(); | |
overview.author.name = "Ian Jackson"; | |
System.Xml.Serialization.XmlSerializer writer = | |
new System.Xml.Serialization.XmlSerializer(typeof(Book)); | |
var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "//TestXML.xml"; | |
System.IO.FileStream file = System.IO.File.Create(path); | |
writer.Serialize(file, overview); | |
file.Close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment