gpt4 book ai didi

c# - 在 Linq-to-xml 中使用 xname

转载 作者:太空狗 更新时间:2023-10-29 18:02:52 24 4
gpt4 key购买 nike

我正在编写一些代码,以从我网站上的 rss 提要列表(已解析)生成一个 opml 文件。用户将从我网站上的 rss 提要数据网格中选择复选框,当按下按钮时,繁重的工作就会发生。

无论如何,我有这样的代码:

     foreach (var v in list)
{
XName xname;

doc.Element("channel").Add(
new XElement("title", v.Name),
new XElement("description", "First Article Description"),
new XElement("pubDate", DateTime.Now.ToUniversalTime()),
new XElement("guid", Guid.NewGuid()));

}

list 是提要对象的集合(例如 hanselman rss 提要、codinghorror rss 提要等)。数据网格将有一个复选框并按下该网格下方的按钮,上面的代码将执行(我还获得了 xml 声明等的代码)。

当我使用 Element(...) 方法时,我需要提供 XName。这有一个我不能使用的内部构造函数。如何传入这个参数?

最佳答案

您还可以将 namespace 括在花括号中:

XName name = "{http://schemas.xyz.com/namespaceUri}tagName";

关于c# - 在 Linq-to-xml 中使用 xname,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1316308/

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