Friday, 15 January 2010

How to Process XML response in rails -



How to Process XML response in rails -

i building simple domain name app connects dynadot xml api. using httparty create request api code below

def index reqd = httparty.get("https://api.dynadot.com/api3.xml?key=xxxxx&command=search&domain0=mydomain.com&domain1=mydomain.net").body puts reqd end

and next output

<results> <searchresponse><searchheader> <successcode>0</successcode> <domainname>mydomain.com</domainname> <status>success</status> <available>no</available> </searchheader></searchresponse> <searchresponse><searchheader> <successcode>0</successcode> <domainname>mydomain.net</domainname> <status>success</status> <available>no</available> </searchheader></searchresponse></results>

is possible pass in rails , represent array can loop through domain names , display them list available or not , domain name beside when converted html. if possible know how code sample or explanation. give thanks you.

here's simple way this:

class="lang-rb prettyprint-override"># require 'active_support/core_ext/hash/conversions' hash = hash.from_xml(your_xml)

the your_xml variable string 1 pasted. parse xml using nokogiri , utilize #to_s , pass argument hash#from_xml

ruby-on-rails-3 ruby-on-rails-4 xml-parsing xml-serialization

No comments:

Post a Comment