【发布时间】:2011-03-26 06:51:21
【问题描述】:
我已使用 Visual Studio 2008 成功创建了 XML,但 Visual Studio 2010 中的 Windows Phone 7 应用程序似乎不支持相同的语法。
我正在使用以下命名空间:
using System.Xml.Linq;
using System.Xml;
我的代码是:
private const string filename = @"c:\sampledata.xml";
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
settings.NewLineOnAttributes = true;
byte[] byteArray = Encoding.UTF8.GetBytes(filename);
MemoryStream strm = new MemoryStream(byteArray);
XmlWriter writer = XmlWriter.Create(strm, settings);
writer.WriteStartDocument(true);
writer.WriteComment("sample XML");
writer.WriteStartElement("root-node");
writer.WriteElementString("child-node", "The element value");
writer.WriteStartElement("next-child");
writer.WriteAttributeString("some-attribute", "A value");
writer.WriteAttributeString("another-attribute", "Another value");
writer.WriteValue("The next element value");
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
我收到以下错误:
内存流不可扩展
当我用 Google 搜索时,我找不到解决方案。我不知道我的方法是否正确。请指导我进一步进行....
【问题讨论】:
标签: c# xml visual-studio-2010 windows-phone-7