XPath中的实现条件 [英] Implementing condition in XPath

查看:88
本文介绍了XPath中的实现条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XML文件

<?xml version="1.0" encoding="UTF-8"?>
<xml>
  <events date="12/12/2010">
    <event>
      <title>JqueryEvent</title>
      <description>
        easily
      </description>
    </event>
  </events>
  <events date="14/12/2011">
    <event>
      <title>automatically onBlur</title>
      <description>
        when a date is selected. For an inline calendar, simply attach the datepicker to a div or span.
      </description>
    </event>
  </events>
</xml>

我正在使用此Xpath选择节点

And I am using this Xpath to select the nodes

$xml   = simplexml_load_file($file);
$nodes = $xml->xpath('//xml/events');

它将选择所有节点.我想根据日期选择节点.

It will select all the nodes.I want to select the nodes based on the date.

推荐答案

在xpath表达式中指定日期,

Specify the date in the xpath expression,

$nodes = $xml->xpath('//xml/events[@date="14/12/2011"]');

将仅选择示例中的最后一个事件节点

would select only the last events-node in the example

这篇关于XPath中的实现条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆