gpt4 book ai didi

c# - 从 XML 字符串生成 XElement 代码

转载 作者:行者123 更新时间:2023-11-30 15:37:43 25 4
gpt4 key购买 nike

有什么方法可以从给定的 XML 字符串在 C# 中生成 XElement 表示?

基本上我想要实现的是从这样的字符串开始:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0">
<channel>
<title>RSS Channel Title</title>
<description>RSS Channel Description.</description>
<link>http://aspiring-technology.com</link>
<item>
<title>First article title</title>
<description>First Article Description</description>
</item>
</channel>
</rss>

像这样的字符串:

XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement("rss",
new XAttribute("version", "2.0"),
new XElement ("channel",
new XElement("title", "RSS Channel Title"),
new XElement("description", "RSS Channel Description."),
new XElement("link", "http://aspiring-technology.com"),
new XElement("item",
new XElement("title", "First article title"),
new XElement("description", "First Article Description")
)
)
);

非常感谢任何提示!

最佳答案

ReSharper 2016.1 具有将字符串转换为 XElement 或 XDocument 对象的上下文操作。

gif example how it works

关于c# - 从 XML 字符串生成 XElement 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12276684/

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