0

This is my XML:

<Group ID="1" ParentGroupID="5" targetHostname="" Name="127.0.0.1[192.168.0.8]:80 | 81 | 80" LoadBalancerMaxConnections="0" State="1" ProtocolType="TCP" Description="HttpProxy" ProtocolName="HttpProxy">
  <Instance ID="1" Type="CrossProtocol.CrossProtocolHost" NoDelay="False" KeepAlive="False" LocalIP="0.0.0.0" LocalPort="80" ServiceID="-1" MaxConnections="0" RemoteIP="127.0.0.1" RemotePort="80" CallBackPort="81" Description="HttpProxy" DesignatedIP="1.1.1.1" ProtocolName="HttpProxy">
    <IPAddressRestriction Name="Restrict or grant access to services based on IP addresses" Type="0" Description="">
    </IPAddressRestriction>
  </Instance>
  <Instance ID="2" Type="CrossProtocol.CrossProtocolHost" LocalIP="0.0.0.0" LocalPort="81" ServiceID="0" MaxConnections="0" Description="HttpProxy">
    <IPAddressRestriction Name="IPAddress Restriction" Type="0" Description="Restrict or grant access to services based on IP addresses">
    </IPAddressRestriction>
  </Instance>
</Group>

I want to get the value of RemotePort out of the XML to use as a variable, I tried using :

doc.xpath("//Instance/RemotePort")

But I get this as response:

doc.xpath("//Instance/RemotePort")
=> []

What did I do wrong ?

1 Answer 1

3
doc.xpath('//Instance/@RemotePort')
# => [#<Nokogiri::XML::Attr:0x11615d8 name="RemotePort" value="80">]

doc.xpath('//Instance/@RemotePort').map(&:value)
# => ["80"] 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.