Handsoap: Parsing Attributes


I am using Handsoap to integrate my Rails app with a SOAP web service,
and when parsing the XML in the response, I need to change behavior
depending on an element’s ‘type’ attribute. A snippet of the XML
response is below:

<?xml version="1.0" encoding="UTF-8"?>

<s:Envelope xmlns:s=“http://schemas.xmlsoap.org/soap/envelope/”>




I’ve tried to get the Detail node’s ‘type’ attribute using XPATH the
following ways:

puts (node/“subscriber:Detail”["@type"]).to_s
puts (node/“subscriber:[email protected]:type”).to_s

and using a number of namespace combinations, but no luck. Does
anyone have experience or ideas on parsing XML attribute values using

Thanks in advance!

I just got it to work using:

puts (node/“subscriber:Detail”).xpath("@instance:type").to_s

I forgot to mention that in this case, node was a XMLNodeSelection
instance pointing to . Hopefully this helps
someone else.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs