XPath只从元素中获取文本(PHP)

Apologies if this has been answered before.

I've been trying to construct an XPath expression to retrieve only the text portion from an element such as this (containing text as well as other elements)

...
  <td id="test">
     The text I want.
     <table>
        Things I do not want
        .....
        .....
  </td>

I haven't been able to find any way to separate "the text I want" from the other content inside the element.

Your help is appreciated.

1个回答



// td / text()</ code>应在第一个节点规则下检索td下的文本节点子节点 实际上,这将是你想要的,否则,如果你想要一个特定的文本孩子,用方括号过滤它</ p>
</ div>

展开原文

原文

//td/text() should retrieve the text node children under td, when the first node rule is in effect, this will be the one you want, otherwise, filter this with square brackets if you want a particular text child

dounanyin3179
dounanyin3179 谢谢,这很有效。
接近 11 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐