I’m attempting to write some data from an object to an XML document and am following a tutorial online, however I have run into a problem which I can’t seem to fathom, the code I’m using to initiate the creation of the document isusing (XmlWriter writer = XmlWriter.Create("myData.xml")) and I’m getting an error with the “myData.xml”, the errors I get are:
The best overload method match for 'System.Xml.XmlWriter.Create(System.Xml.XmlWriter)'
has some invalid arguments
Argument 1: cannot convert from 'string' to 'System.Xml.XmlWriter'
Is XmlWriter compatible with Windows Phone? And if not will I have to change huge amounts of code that writes to the file?
Edit: Here’s my code
string output = SerializeToString<AppData>(rulesData);
using (XmlWriter writer = XmlWriter.Create(output))
{
writer.WriteStartDocument();
writer.WriteStartElement("myData");
writer.WriteElementString("Starting Cash", rulesData.myStartingCash);
writer.WriteElementString("Land on Go Data", rulesData.myLandOnGo);
writer.WriteElementString("Free Parking Data", rulesData.myFreeParking);
writer.WriteElementString("Full Circuit Data", rulesData.myFullCircuit);
writer.WriteElementString("Auction Data", rulesData.myAuction);
writer.Flush();
writer.WriteEndElement();
writer.WriteEndDocument();
}
Thanks! -Ryan
You can use this code:
Your code doesn’t compile because you pass a string instead of a stream to XmlWriter
Usage: