在Xpath中加入操作

时间:2015-09-04 14:01:50

标签: xml xpath

我正在尝试为基于公共密钥

的操作创建一个Xpath表达式

这是我的XML,我想获得所有网络名称为

的区域
  

'网络2'

XML:

<tmp>
    <network>
        <id>1</id>
        <name>network-1</name>
    </network>
    <network>
        <id>2</id>
        <name>network-2</name>
    </network>
    <network>
        <id>3</id>
        <name>network-3</name>
    </network>
    <zone>
        <network-id>1</network-id>
        <zone-name>zone1</zone-name>
    </zone>
    <zone>
        <network-id>1</network-id>
        <zone-name>zone2</zone-name>
    </zone>
    <zone>
        <network-id>2</network-id>
        <zone-name>zone3</zone-name>
    </zone>
</tmp>

在network-id中是zone的外键。

我尝试使用下面的xpath表达式,但它不起作用:

/tmp/zone[contains(tmp/network/name,'network-2')]

1 个答案:

答案 0 :(得分:3)

这部分取自networ-2的id

{:timestamp=>"2015-09-04T16:25:52.976000+0200", :message=>"SSL Error", :exception=>#<OpenSSL::SSL::SSLError: Unrecognized SSL message, plaintext connection?>, :backtrace=>["org/jruby/ext/openssl/SSLSocket.java:238:in `accept'", "C:/elkstack/logstash-1.5.3/vendor/jruby/lib/ruby/shared/jopenssl19/openssl/ssl-internal.rb:142:in `accept'", "C:/elkstack/logstash-1.5.3/vendor/bundle/jruby/1.9/gems/logstash-input-tcp-1.0.0/lib/logstash/inputs/tcp.rb:182:in `run_server'", "C:/elkstack/logstash-1.5.3/vendor/bundle/jruby/1.9/gems/logstash-input-tcp-1.0.0/lib/logstash/inputs/tcp.rb:170:in `run'", "C:/elkstack/logstash-1.5.3/vendor/bundle/jruby/1.9/gems/logstash-core-1.5.3-java/lib/logstash/pipeline.rb:177:in `inputworker'", "C:/elkstack/logstash-1.5.3/vendor/bundle/jruby/1.9/gems/logstash-core-1.5.3-java/lib/logstash/pipeline.rb:171:in `start_input'"], :level=>:error}
{:timestamp=>"2015-09-04T16:25:53.992000+0200", :message=>"SSL Error", :exception=>#<OpenSSL::SSL::SSLError: Unrecognized SSL message, plaintext connection?>, :backtrace=>["org/jruby/ext/openssl/SSLSocket.java:238:in `accept'", "C:/elkstack/logstash-1.5.3/vendor/jruby/lib/ruby/shared/jopenssl19/openssl/ssl-internal.rb:142:in `accept'", "C:/elkstack/logstash-1.5.3/vendor/bundle/jruby/1.9/gems/logstash-input-tcp-1.0.0/lib/logstash/inputs/tcp.rb:182:in `run_server'", "C:/elkstack/logstash-1.5.3/vendor/bundle/jruby/1.9/gems/logstash-input-tcp-1.0.0/lib/logstash/inputs/tcp.rb:170:in `run'", "C:/elkstack/logstash-1.5.3/vendor/bundle/jruby/1.9/gems/logstash-core-1.5.3-java/lib/logstash/pipeline.rb:177:in `inputworker'", "C:/elkstack/logstash-1.5.3/vendor/bundle/jruby/1.9/gems/logstash-core-1.5.3-java/lib/logstash/pipeline.rb:171:in `start_input'"], :level=>:error}

,这会找到带有该ID的区域名称

/tmp/network[name[contains(., 'network-2')]]/id 

完整的xpath可能是这样

/tmp/zone[network-id= ?? ]/zone-name