gpt4 book ai didi

c# - 如何在 Silverlight 中创建 XML 文档

转载 作者:太空宇宙 更新时间:2023-11-03 22:02:41 24 4
gpt4 key购买 nike

我似乎不知道如何在 SilverLight 中创建新的 XML 文件。我尝试使用 XMLTextWriter 和 XMLDocument,但在两者上我都收到错误“在当前上下文中不存在”

我正在使用 System.Xml,我可以使用 XMLWriter 和 XMLReader,但我终究无法弄清楚我做错了什么。有人可以指出我正确的方向吗?

谢谢!

最佳答案

您正在寻找 Linq to Xml 和 XDocument类(class)。来自 MSDN 的示例:

XDocument srcTree = new XDocument(
new XComment("This is a comment"),
new XElement("Root",
new XElement("Child1", "data1"),
new XElement("Child2", "data2"),
new XElement("Child3", "data3"),
new XElement("Child2", "data4"),
new XElement("Info5", "info5"),
new XElement("Info6", "info6"),
new XElement("Info7", "info7"),
new XElement("Info8", "info8")
)
);

这是使用 System.Xml.Linq 命名空间。

您需要在 Silverlight 项目中添加对程序集 System.Xml.Linq.dll 的引用:

enter image description here

关于c# - 如何在 Silverlight 中创建 XML 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9548368/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com