Xpath 计数并比较日期时间
下面是我的 xml...
我想做的是使用 XPATH 和计数表达式..我想要统计 xml 中的日期何时与今天的日期匹配。例如,今天的日期是“2011-05-05”。任何与该日期匹配的消息都有一个计数并返回一个整数。所以答案是 NumberofTodaysMessages = 2。
<Response>
<run_id>1</run_id>
<message>
<timestamp>2011-05-05T10:50:00.46875+00:00</timestamp>
<event_type>Information</event_type>
<operation>LoadProjects</operation>
<error_code />
<details>LoadProjects request detected</details>
</message>
<message>
<timestamp>2011-05-05T10:50:02.296875+00:00</timestamp>
<event_type>Error</event_type>
<operation>Processor.InitaliseDCFiles</operation>
<error_code />
<details>some error details</details>
</message>
<message>
<timestamp>2011-11-10T10:50:02.296875+00:00</timestamp>
<event_type>Debug</event_type>
<operation>Processor.InitaliseDCFiles</operation>
<error_code />
<details>some details</details>
</message>
<Response>
我将如何在 XPATH 中解决这个问题?
计数(/响应/消息/时间戳[@DateTime.Now()])
Below is my xml...
What I am trying to do is using XPATH and count expression.. I want a count of when a date in xml matches Todays date. So for example Todays Date is "2011-05-05".. Any messages that match this date have a count and return a integer. so answer would be NumberofTodaysMessages = 2.
<Response>
<run_id>1</run_id>
<message>
<timestamp>2011-05-05T10:50:00.46875+00:00</timestamp>
<event_type>Information</event_type>
<operation>LoadProjects</operation>
<error_code />
<details>LoadProjects request detected</details>
</message>
<message>
<timestamp>2011-05-05T10:50:02.296875+00:00</timestamp>
<event_type>Error</event_type>
<operation>Processor.InitaliseDCFiles</operation>
<error_code />
<details>some error details</details>
</message>
<message>
<timestamp>2011-11-10T10:50:02.296875+00:00</timestamp>
<event_type>Debug</event_type>
<operation>Processor.InitaliseDCFiles</operation>
<error_code />
<details>some details</details>
</message>
<Response>
How would I go about this in XPATH??
count(/Response/message/Timestamp[@DateTime.Now()])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
xpath 可以是:
Today = "2011-11-05" // 用日期库替换字符串中的“today”
xpath = "Response/message/timestamp[starts-with(text()='"+today+" ')]"
the xpath could be:
today = "2011-11-05" // replace by "today" in a string with your date library
xpath = "Response/message/timestamp[starts-with(text()='"+today+"')]"
C# 实现了 XPath 2.0,对吗?那么您应该可以使用所有这些函数。
C# implements XPath 2.0, right? Then you should have all these functions available.