根据兄弟节点的值选择节点 [英] Select node based on sibling's value

查看:35
本文介绍了根据兄弟节点的值选择节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要 XPath 语法(用于 simplexml)来搜索 LayoutPosNo 元素的内容,该元素与数字 1001 完全匹配并返回同级 Descript 中的文本代码>元素.LayoutPosNo 都是唯一的,所以我只需要第一个匹配.

I need XPath syntax (for use in simplexml) for searching the contents of the LayoutPosNo element that matches exactly, say, the number 1001 and returning the text in the sibling Descrip element. The LayoutPosNo's are all unique, so I only need the first match.

这里是 XML 的结构:

Here is the structure of the XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <record>
        <LayoutPosNo>10</LayoutPosNo>
        <Descrip>This is the red room</Descrip>
    </record>
    <record>
        <LayoutPosNo>993</LayoutPosNo>
        <Descrip>This is the yellow room</Descrip>
    </record>
    <record>
        <LayoutPosNo>1001</LayoutPosNo>
        <Descrip>This is the purple room</Descrip>
    </record>
</data-set>

推荐答案

以下 XPath

/data-set/record[LayoutPosNo = 1001]/Descrip/text()

会选择

This is the purple room

根据要求.

这篇关于根据兄弟节点的值选择节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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