有沒有什麼辦法從給定的XML字符串中生成C#中的XElement
表示?從XML字符串生成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")
)
)
);
真的很感激任何提示!
據我所知你正試圖建立一個代碼生成器。您可能會提及關鍵字「代碼生成」以避免誤導性答案。 –