在我的项目中,我想创建一个xml文件并保存,然后检索xml文件。那是我的代码:
XDocument doc = new XDocument(new XDeclaration("1.0", "iso-8859-1", "yes"),
new XElement("checkout",
new XElement("currency", "BRL"),
new XElement("items",
new XElement("item",
new XElement("id", "0001"),
new XElement("description", "Dízimo"),
new XElement("amount", _amount),
new XElement("quantity", "1"))),
//new XElement("weight", "50"),
new XElement("reference", _reference),
new XElement("sender",
new XElement("name", _name),
new XElement("email", _email),
new XElement("phone",
new XElement("areacode", _areacode),
new XElement("number", _number))),
new XElement("shipping",
new XElement("type", "1"),
new XElement("address",
new XElement("street", _street),
new XElement("number", _numberHome),
new XElement("complement", _complement),
new XElement("district", _district),
new XElement("postalcode", _postalcode),
new XElement("city", _city),
new XElement("state", _state),
new XElement("country", "BRA")))));
using (var storage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (Stream stream = storage.CreateFile(@"c:\Temp\data.xml"))
{
doc.Save(stream);
}
}
但是,在我使用的另一个课程中:
var xml = XDocument.Load("a.xml").ToString();
var content = new StringContent(
xml,
Encoding.GetEncoding("ISO-8859-1"),
"application/xml");
从namePath读取xml文件,但现在我想从IsolatedStorageFile中读取,如何转换流对象,以便我可以在XDocument.Load(stream)
内部使用