Created
December 8, 2012 04:56
-
-
Save jonpryor/4238677 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<ArrayOfItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | |
<Item Completed="true"> | |
<DoItem>fds</DoItem> | |
</Item> | |
<Item Completed="false"> | |
<DoItem>Find</DoItem> | |
</Item> | |
</ArrayOfItem> |
This file contains hidden or 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
// Sample program: | |
using System; | |
using System.Collections.Generic; | |
using System.Xml; | |
using System.Xml.Serialization; | |
public class Item { | |
public string DoItem; | |
[XmlAttribute ()] | |
public bool Completed; | |
} | |
class Demo { | |
public static void Main () | |
{ | |
var list = new List<Item> { | |
new Item {DoItem = "fds", Completed=true}, | |
new Item {DoItem = "Find", Completed=false}, | |
}; | |
Serialize (list); | |
} | |
static void Serialize(List<Item> list) | |
{ | |
Type[] itemTypes = { typeof(Item) }; | |
XmlSerializer serializer = new XmlSerializer(typeof(List<Item>), itemTypes); | |
// FileStream fs = new FileStream("ToDoList.xml", FileMode.Create); | |
serializer.Serialize(Console.Out, list); | |
// fs.Close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment