dongmaopan5738 2014-02-20 13:54
浏览 42
已采纳

XPath和PHP DomDocument - 如何选择具有特定标记和属性的所有子项

I have the element $paragraph in my DOMDocument:

<p class=4textlist>
    String 1
    <p class=4textlist> String 1.1</p>
<p class=4textlist>String 1.2</p>
    String 2
</p>

At one moment, I selected the element and I would like to get all the p tags from this elements that have the class "4textlist".

For that, I have try:

$result = $xpath->query('descendent::p[@class="4textlist"]', $paragraph);

But this is not working. Any idea please ?

  • 写回答

2条回答 默认 最新

  • dsfjnxjlbqv9812 2014-02-20 13:58
    关注

    You've got a typo in your query, descendent vs. descendant. descendant::p[@class="4textlist"] works fine.

    You might also consider .//p[@class="4textlist"].

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改