xml - Postgresql xpath 搜索属性和元素组合

标签 xml postgresql xpath

我能够使用 Postgresql(9.4.x) xpath 搜索来匹配 xml 属性或元素。是否可以搜索属性和元素值的组合?

<name>
  <firstname>test</firstname>
  <lastname>user</lastname>
  <role num="10">admin</role>
  <role num="8">readonly</role>
</name>

我试图在上面的示例 xml 中将管理员角色与数字 10 匹配,下面的查询也确实为 8 位管理员组合返回 TRUE。

select xpath('//role/@num="8" and //role/text()="admin"', '<above xml>');

请建议是否有更好的方法来匹配精确的索引组合。

谢谢。

最佳答案

I was trying to match admin role with number 10

尝试:

'//role[@num="10" and text()="admin"]'

或者如果请求管理员的 name 元素:

'//name[role[@num="10" and text()="admin"]]'

关于xml - Postgresql xpath 搜索属性和元素组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36869044/

相关文章:

c - PostgreSQL:如何实现 GIN?

bash - 如何使用 xmllint 和 xpath 输出多行

java - 如何在manifest.xml 文件中找到基本组件类?

python - 用 python 解析 lxml : how to with objectify

regex - 有没有办法有条件地替换字符串中的第一个 '/' ?

xml - 仅当前面的兄弟节点的子节点不是某个节点时,XSL 模板才匹配

XSLT:检查列表中是否存在值

c++ - 通过 TinyXML 深度复制 XML

java - E/RecyclerView : No adapter attached; skipping layout not showing the data in recyclerview

sql - Postgresql:替代 WHERE IN 各自的 WHERE NOT IN