xml - 通过 XPath 根据条件获取 XML 值
问题描述
下面是我的 XML:
<bookstore>
<book>
<title>Python</title>
<price>29.99</price>
</book>
<book>
<title>XML</title>
<price>29.99</price>
<feature>
<description>Learn XML</description>
</feature>
</book>
</bookstore>
如果description
"Learn XML"
匹配,那么它应该返回title
"XML"
.
解决方案
试试这个 XPath
//description[text() = 'Learn XML']/../../title
它匹配所有内容为“Learn XML”的元素并获取description
其.text()
title
推荐阅读
- windows - JetBrains Mono 在 Android Studio 中不可用
- ios - Swift:如何从选定的单元格中获取数据?
- python - 从仅获取最后一行的表中提取数据
- r - 有没有办法将选择器/selectInput 与闪亮的可编辑、反应式 DT 结合使用?
- laravel - 从数据库中获取在 laravel 中具有特定列值的所有行
- ruby-on-rails - 未定义的方法 `slug_limit=' 用于友好 ID
- azure-logic-apps - Azure AD 属性“备用电子邮件地址”是否有 Power Automate Flow 表达式
- excel - 关于 INDIRECT 函数的问题
- bash - 期望脚本切割/中继线
- html - 使用CSS将跨度中的文本与Angular Material图标的底部对齐?