将基于同级值的节点与 XPath 匹配 [英] Matching a node based on a sibling's value with XPath

查看:34
本文介绍了将基于同级值的节点与 XPath 匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个像这样的 XML 文档:

Having a XML document like this:

<?xml version="1.0" encoding="UTF-8"?>
<records type="array">
  <record>
    <name>svn</name>
    <record-type>A</record-type>
    <ttl type="integer">86400</ttl>
    <zone-id type="integer">69075</zone-id>
    <aux type="integer">0</aux>
    <id type="integer">xxx</id>
    <active>Y</active>
    <data>xxx.xxx.xxx.xxx</data>
  </record>
  <record>
    <name>domain.tld.</name>
    <record-type>NS</record-type>
    <ttl type="integer">86400</ttl>
    <zone-id type="integer">xxx</zone-id>
    <aux type="integer">0</aux>
    <id type="integer">xxx</id>
    <active>Y</active>
    <data>domain.tld.</data>
  </record>
  <record>
    <name>blog</name>
    <record-type>A</record-type>
    <ttl type="integer">86400</ttl>
    <zone-id type="integer">xxx</zone-id>
    <aux type="integer">0</aux>
    <id type="integer">xxx</id>
    <active>Y</active>
    <data>xxx.xxx.xxx.xxx</data>
  </record>
</records>

如何将所有具有兄弟 /records/record/record-type/records/record/name 与值 A 匹配?

How to match all the /records/record/name having as sibling /records/record/record-type with the value A?

推荐答案

找到了:

/records/record/name[../record-type/text() = "A"]

这篇关于将基于同级值的节点与 XPath 匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆