gpt4 book ai didi

xpath - 使用 XPath 解析包含冒号的元素名称

转载 作者:行者123 更新时间:2023-12-03 15:27:36 25 4
gpt4 key购买 nike

所以我试图解析一些 WootAPI与 XPath。我遇到的一个问题是一些元素的名称中有冒号,例如 woot:pricewoot:condition .现在,尝试使用 XPath //rss/channel/item/woot:price不会抓取元素 woot:price 的内容,因为冒号,我想。无论如何,我该怎么做才能得到它?

最佳答案

冒号是因为元素具有命名空间前缀并绑定(bind)到 Woot 命名空间。

你应该阅读 XML namespaces and how they affect XPATH and XSLT .

如果要在 XPATH 中引用 Woot 元素,则需要:

  • 声明 Woot 命名空间 http://www.woot.com/这样当您在 XPATH 中使用该 namespace 前缀时,它就会被理解。
  • 使用更通用的 XPATH 语句,该语句使用使用 local-name() 的谓词过滤器和 namespace-uri()匹配元素。
  • //rss/channel/item/*[local-name()='price' and namespace-uri()='http://www.woot.com/']
  • 关于xpath - 使用 XPath 解析包含冒号的元素名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4282147/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com