gpt4 book ai didi

linq-to-xml - Stackoverflow 将 Linq 提供给 XML 过滤

转载 作者:行者123 更新时间:2023-12-04 06:27:47 25 4
gpt4 key购买 nike

我有这个 XML:

<feed xmlns="http://www.w3.org/2005/Atom" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:re="http://purl.org/atompub/rank/1.0">
<title type="text">Recent Questions - Stack Overflow</title>
<link rel="self" href="http://stackoverflow.com/feeds" type="application/atom+xml" />
<link rel="alternate" href="http://stackoverflow.com/questions" type="text/html" />
<subtitle>most recent 30 from stackoverflow.com</subtitle>
<updated>2011-04-28T13:53:52Z</updated>
<id>http://stackoverflow.com/feeds</id>
<creativeCommons:license>http://www.creativecommons.org/licenses/by-nc/2.5/rdf</creativeCommons:license>
<entry>
<id>http://stackoverflow.com/questions/5819742/how-do-i-run-a-slow-running-batch-asynchronously-specifically-a-svn-post-commit</id>
<re:rank scheme="http://stackoverflow.com">0</re:rank>
<title type="text">How do I run a slow running batch Asynchronously, specifically a SVN post-commit?</title>
<category scheme="http://stackoverflow.com/feeds/tags" term="windows"/><category scheme="http://stackoverflow.com/feeds/tags" term="svn"/><category scheme="http://stackoverflow.com/feeds/tags" term="batch"/><category scheme="http://stackoverflow.com/feeds/tags" term="post-commit"/>
<author>
<name>digiguru</name>
<uri>http://stackoverflow.com/users/5055</uri>
</author>
<link rel="alternate" href="http://stackoverflow.com/questions/5819742/how-do-i-run-a-slow-running-batch-asynchronously-specifically-a-svn-post-commit" />
<published>2011-04-28T13:53:48Z</published>
<updated>2011-04-28T13:53:48Z</updated>
<summary type="html">
whatever1
</summary>
</entry>
<entry>
<id>http://stackoverflow.com/questions/5818592/wxpython-making-a-panel-not-accessible-through-tab</id>
<re:rank scheme="http://stackoverflow.com">0</re:rank>
<title type="text">wxPython making a panel not accessible through tab</title>
<category scheme="http://stackoverflow.com/feeds/tags" term="wxpython"/><category scheme="http://stackoverflow.com/feeds/tags" term="wxglade"/>
<author>
<name>ccwhite1</name>
<uri>http://stackoverflow.com/users/588892</uri>
</author>
<link rel="alternate" href="http://stackoverflow.com/questions/5818592/wxpython-making-a-panel-not-accessible-through-tab" />
<published>2011-04-28T12:30:02Z</published>
<updated>2011-04-28T13:53:34Z</updated>
<summary type="html">
whatever 2
</summary>
</entry>
</feed>

是来自 StackOverflow 的最近订阅源的 RSS 的一部分。

我需要取回整个 xml(我正在使用 Linq to XML。),但只有具有“更新”属性且值小于或等于通过参数传递的 DateTime 的条目。

我这样得到xml:
XDocument recientes = XDocument.Load(ObtenerFeedsRecientes());
recientes = recientes.Root.Elements().DontKnowWhatToDo();

有人可以给我一个如何做到这一点的方法吗?

谢谢!

最佳答案

XDocument recientes = XDocument.Load(ObtenerFeedsRecientes());

XNamespace atomNS = "http://www.w3.org/2005/Atom";

var updates = from entry in recientes.Root.Elements(atomNS + "entry")
where DateTime.Parse(entry.Element(atomNS + "updated").Value) <= parameter
select entry;

应该做的伎俩。这假设 parameter类型为 DateTime

关于linq-to-xml - Stackoverflow 将 Linq 提供给 XML 过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5825724/

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