有什么方法可以从给定的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")
)
)
);
真的很感谢任何提示!
解决方法:
看看这个XElement/XDocument Code Generator.
它使用XSLT转换从XML生成c#代码.
如果我自己做的话,我可能会以同样的方式做.