如何获取下一个 XML 元素值?
XDocument coordinates = XDocument.Load("http://feeds.feedburner.com/TechCrunch");
System.IO.StreamWriter StreamWriter1 = new System.IO.StreamWriter(DestFilePath);
foreach (var coordinate in coordinates.Descendants("guid"))
{
string Links = coordinate.Value;
StreamWriter1.WriteLine(Links + Environment.NewLine );
}
StreamWriter1.Close();
使用上述 URL (http://feeds.feedburner.com/TechCrunch) 的代码我可以获得所有链接,但我还想获得<描述>和<内容:编码>元素值。
问题是我想获得<描述>等值及其 guid 值,以便我可以将它们连续存储(在数据库中)。
我应该为此目的使用LINQ吗? 但请如何告诉?
XDocument coordinates = XDocument.Load("http://feeds.feedburner.com/TechCrunch");
System.IO.StreamWriter StreamWriter1 = new System.IO.StreamWriter(DestFilePath);
foreach (var coordinate in coordinates.Descendants("guid"))
{
string Links = coordinate.Value;
StreamWriter1.WriteLine(Links + Environment.NewLine );
}
StreamWriter1.Close();
Using this code for the above URL (http://feeds.feedburner.com/TechCrunch) i am able to obtain all the links but i also want to obtain <description> and <content:encoded> element values.
The problem is that i want to obtain <description> etc values along with their guid values so that i can store them in serially (in database).
Should i use LINQ of something for this purpose ?
But how please tell ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该迭代每个“项目”并检索其属性。不要忘记“内容”命名空间。
You should iterate over each "item" and retrieve its properties. Do not forget about the "content" namespace.
一种方法是您可以尝试单独枚举它们,
One way is you can try enumerating them individualy,
不确定,但尝试 .DescendantsAndSelf()
Not sure but try .DescendantsAndSelf()
我建议您使用 XPATH 迭代每个 //content/item,然后获取该项目的 guid、内容等。
I suggest that you use XPATh to iterate over each //content/item and then get that item's guid, content, etc.