Closed renjithnair1985 closed 12 years ago
I had the same issue with default xml parser. Seems the httparty default xml parser isn't a one for one implemenation of the Crack::XML.parse functionality. The crack xml parser allows you to get at attributes in the hash. The httparty parsed response doesn't, I've verified this in rspec tests because a project I'm working on requires me to parse the attributes for processing certain logic.
<root><action condition="email">threshold not met, email response</action></root>
Here's a workaround to get at xml attributes using Crack::XML.parse:
def self.submit(submission, setting)
Crack::XML.parse(get(setting.uri, query: build_insert_query_string(submission, setting)))
end
xml_doc = Wonky::Webservice.submit(submission, setting)
using the crack parser you would get at the attributes like so:
puts xml_doc['root']['action'].attributes
puts xml_doc['root']['action'].attributes['condition'] # condition is an attribute of action tag
So to get this working as advertised, Httparty needs some tests for the xml parsing scenarios involving attributes to make sure it's implementing the full Crack::XML.parse functionality for xml attributes.
I have the following node in my xml request
"Distance direction="SW" unit="KMS">4.6</Distance"
But when I try to convert it to hash I am only getting it as :Distance => 4.6. Is it possible to get the has as something like
:Distance => {:direction => "SW", :unit => "KMS", :content => "4.6"}
Thanks