为了账号安全,请及时绑定邮箱和手机立即绑定

Xpath:如果存在多个子项,则选择多个父项

Xpath:如果存在多个子项,则选择多个父项

繁华开满天机 2021-11-04 10:50:49
我在将 xml 文件的多个值放入 html 表时遇到问题。我想使用以下 xpath 表达式获得具有 tcp.TcpDispatcherProperties 的 destinationConnectors 属性的所有父项的名称:"/serverConfiguration/channels/channel[destinationConnectors/connector/properties[@class='com.mirth.connect.connectors.tcp.TcpDispatcherProperties']]/name"用这个表达:父级只显示一次,即使它有多个具有此类的目的地问题是,如果有多个 destinationConnectors [1..n],我只会在我的 html 表中一次从 //channels/name 获取父级。例如,我想用 xml.evaluate 在 Javascript 中显示的内容,如果我有 3 个频道 - Channel1 有 1 个目的地,Channel2 有 2 个目的地:------------  -------------  -------------Channel1Name | Channel2Name | Channel2Name------------  -------------  -------------Destination1  Destination2a  Destination2b我想要的输出是:Channel1Name 来自“/serverConfiguration/channels/channel/name”Channel2Name 来自“/serverConfiguration/channels/channel/name”Channel2Name 来自“/serverConfiguration/channels/channel/name”不是频道名称频道名称
查看完整描述

1 回答

?
陪伴而非守候

TA贡献1757条经验 获得超8个赞

以下 xpath 查询返回您需要的内容:

//channel/destinationConnectors/connector/properties[@class='com.mirth.connect.connectors.tcp.TcpDispatcherProperties']/concat(../../../name, ' : ',  ../name)

描述:

  • //channel

    对于channel任何地方的每个元素

  • /destinationConnectors/connector

    下降到properties通过destinationConnectors/connector/

  • /properties[@class='com.mirth.connect.connectors.tcp.TcpDispatcherProperties']

    选择每个找到properties的属性class==c.m.c.c.t.TcpDispatcherProperties

  • /concat(../../../name, ' : ',  ../name)

    concat()盛大,盛大父母channel name与父connector name元素

将返回:

Channel1 : Destination 1
Channel2 : Destination 2a
Channel2 : Destination 2b

更新示例:http : //xpather.com/o3eFcOCg


查看完整回答
反对 回复 2021-11-04
  • 1 回答
  • 0 关注
  • 195 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信