Windows phone XDocument xml serialization

I'm creating a Windows Phone 8.1 app, and I need to serialize my data to XML.

I have two functions; the first one is creating a document where I can later put my retrieved data.

public async Task make() { using (var questions = await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync( "data.xml", CreationCollisionOption.OpenIfExists)) { XDocument xml = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XElement("Root") ); xml.Save(questions); } } 

The second one is making serialization to my xml file:

public async Task serial(Tsk tak) { using (var questions = await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync( "data.xml", CreationCollisionOption.OpenIfExists)) { XDocument xml = XDocument.Load(questions); xml.Root.Add(new XAttribute("Date", tak.Date), new XElement("time", tak.Time), new XElement("text", tak.Text) ); xml.Save(questions); } } 

The first xml function is making this code:

<?xml version="1.0" encoding="utf-8" standalone="yes"?> <root /> 

When I'm running the second function I've got this error: root element is missing. Can anyone tell me how I can get this serialization to work?

by ChiroV3 via /r/csharp

Leave a Reply