节点内内容的XPath表达式,直到遇到带有字符串的节点为止 - php

我正在寻找XPath表达式来获取没有引用部分的文章内容。我希望文章部分中的所有内容都可以使用,直到出现<p>标记,并且其中带有“参考”为止。

//root/main/article/following-sibling::p[.="References"]
<root>
    <main>
        <article>
            <p>
               The stunning increase in homelessness announced in Los Angeles 
               this week — up 16% over last year citywide — was an almost  an 
               incomprehensible conundrum given the nation's booming economy 
               and the hundreds of millions of dollars that city, county and 
               state officials have directed toward the problem.
            </p>
            <p>
                "We cannot let a set of difficult numbers discourage us 
                or weaken our resolve" Garcetti said.
            </p>
            <p>
                References: Maeve Reston, CNN
            </p>
        </article>
    </main>
</root>

我要寻找的结果如下。

<p>
    The stunning increase in homelessness announced in Los Angeles
    this week — up 16% over last year citywide — was an almost  an
    incomprehensible conundrum given the nation's booming economy
    and the hundreds of millions of dollars that city, county and
    state officials have directed toward the problem.
</p>
<p>
    "We cannot let a set of difficult numbers discourage us
    or weaken our resolve" Garcetti said.
</p>

参考方案

这个XPath

/root/main/article/p[starts-with(normalize-space(),'References')]
                  /preceding-sibling::p

将选择带有“参考”的段落之前的段落。

如果只需要这些/text()元素的文本节点子代,则可以附加p

php Singleton类实例将在多个会话中保留吗? - php

举一个简单的例子,如果我想计算一个不使用磁盘存储的脚本的命中次数,我可以使用静态类成员来执行此操作吗?用户1:<?php $test = Example::singleton(); $test->visits++; ?> 用户2:<?php $test = Example::singleton(); $test->visits+…

php:将分钟取整到最近的四分之一小时,然后执行更多操作 - php

最初的问题是这样的:取分钟数->转换为四分之一小时-> 1个四分之一小时为1个单位->输出单位我今天整天都在整理页面,几分钟前我的大脑就停止工作了,我只是不知道如何输出单位数量。我知道在此网站上发布问题会有所帮助。因此,用户输入的分钟数(不是小时和分钟,而是数分钟),站点需要输出单位数量。单位是一个刻钟。分钟总是四舍五入到最近的四分之一小时…

如何使用php删除基于子属性的XML标签? - php

我有一个像下面的XML<entries> <entry> <title lang="en">Sample</title> <entrydate>0</entrydate> <contents>0</contents> <entrynum&…

PHP OOP概念付诸实践 - php

目前,我所拥有的是一份以程序庄园形式编写的审查表。我想更改一些内容,并希望在此过程中,根据过去的经验,在OOP中,网站的整个审核部分会更好。数据流如下:HTML表单=>提交=> jQuery验证=>? => PHP验证=>添加记录我的问题是要了解将POST数据传递给类的正确方法是使用AJAX / jQuery或使用具有标准感谢页…

PHP:检查谁看过发送的电子邮件? - php

我正在向某些用户发送电子邮件,并且想知道是谁阅读的,这意味着如果有人阅读了该电子邮件,则将维护一个日志文件,其中包含该用户的电子邮件地址以及日期/时间/ IP。为此,我发送一个带有电子邮件(html模板)的javascript函数,当用户打开该电子邮件时,它仅会警告用户的电子邮件地址,例如:for($n=0; $n<sizeof($checkBox);…