XPath 只在直接子节点中选择一种类型的节点 [英] XPath select one type of nodes only in direct child nodes

查看:24
本文介绍了XPath 只在直接子节点中选择一种类型的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许有人可以帮我找到解决问题的方法.我需要在下面的 xml 中执行一个 XPath 查询,它只提取作为直接子节点的字段"节点.在下面的示例中,查询应提取字段 E1F1、E1F2 和 E1F3.到目前为止,我正在运行查询://Field,但我得到了所有字段(包括那些属于我不想要的 E1_1 的字段).

Maybe someone can help me find a solution to my problem. I need to perform an XPath query in the xml below that pulls only the "Field" nodes that are direct child nodes. In the below example, the query should pull fields E1F1, E1F2 and E1F3. So far I am running the query: //Field, but I get all fields (including the ones that belong to E1_1 which I don't want).

<Entity id="E1">
  <Field id="E1F1"></Field>
  <Field id="E1F2"></Field>
  <Field id="E1F3"></Field>
  <Entity id="E1_1">
    <Field id="E1_1F1"></Field>
    <Field id="E1_1F2"></Field>
    <Field id="E1_1F3"></Field>
  </Entity>

谢谢!!

推荐答案

使用绝对 XPath:

Use an absolute XPath:

/Entity/Field

// 将匹配任何地方.如果您使用单个正斜杠,则匹配必须准确.

// will match anywhere. If you use a single forwardslash, the match must be exact.

这篇关于XPath 只在直接子节点中选择一种类型的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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