Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8752827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:18:34+00:00 2026-06-13T13:18:34+00:00

I need to parse some XML-RPC-formatted XML in Ruby. I don’t have access to

  • 0

I need to parse some XML-RPC-formatted XML in Ruby. I don’t have access to the XML-RPC service, I just want to turn an XML string that is returned from such a service into the respective Ruby objects (hashes, arrays, strings etc).

I’ve played around with the built-in XMLRPC stuff (in Ruby 1.9.3), but I don’t get very far:

require 'xmlrpc/parser'
parser = XMLRPC::XMLParser::XMLParser.new

That results in this exception:

LoadError: cannot load such file -- xmltreebuilder
from /Users/johannes/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/johannes/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/johannes/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/xmlrpc/parser.rb:620:in `initialize'
from (irb):2:in `new'
from (irb):2
from /Users/johannes/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `<main>'

I then tried to instantiate different XMLParser subclasses, all to no avail.

Do you have any pointers on how to get this to work? Is it even possible to just parse RPC XML without using the XMLRPC::Client with the built-in library?

Thanks!

Update:

This works, but it is oh-so-very-ugly. This just can’t be right:

require 'xmlrpc/client'
require "rexml/document"

xml = %{<answer>
<value>
<struct>
  <member><name>test</name><value><string>hello</string></value></member>
  <member><name>age</name><value><i4>12</i4></value></member>
  <member>
    <name>requirements</name>
    <value>
      <struct>
        <member>
          <name>confirmation</name>
          <value>
            <array>
              <data>
                <value><string>Bread</string></value>
                <value><string>Butter</string></value>
              </data>
            </array>
          </value>
        </member>
        <member>
          <name>document</name>
          <value>
            <array>
              <data>
                <value><string>Tic</string></value>
                <value><string>Tac</string></value>
                <value><string>Toe</string></value>
              </data>
            </array>
          </value>
        </member>
      </struct>
    </value>
  </member>
  <member><name>width</name><value><i4>10</i4></value></member>
  <member><name>height</name><value><i4>2</i4></value></member>
</struct>
</value>
</answer>}

parser = XMLRPC::XMLParser::REXMLStreamParser::StreamListener.new
parser.parse(xml)

puts "Value (accessor): '#{parser.value}'"
puts "Values (accessor): '#{parser.values}'"
puts "Value (instance_variable_get): '#{parser.instance_variable_get('@value')}'"

There must be a better way!

This is the output:

Value (accessor): ''
Values (accessor): ''
Value (instance_variable_get): '{"test"=>"hello", "age"=>12, "requirements"=>{"confirmation"=>["Bread", "Butter"], "document"=>["Tic", "Tac", "Toe"]}, "width"=>10, "height"=>2}'

This makes my eyes hurt.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:18:35+00:00Added an answer on June 13, 2026 at 1:18 pm

    This is the closest thing to a solution I could find:

    This works, but it is oh-so-very-ugly. This just can’t be right:

    require 'xmlrpc/client'
    require "rexml/document"
    
    xml = %{<answer>
    <value>
    <struct>
      <member><name>test</name><value><string>hello</string></value></member>
      <member><name>age</name><value><i4>12</i4></value></member>
      <member>
        <name>requirements</name>
        <value>
          <struct>
            <member>
              <name>confirmation</name>
              <value>
                <array>
                  <data>
                    <value><string>Bread</string></value>
                    <value><string>Butter</string></value>
                  </data>
                </array>
              </value>
            </member>
            <member>
              <name>document</name>
              <value>
                <array>
                  <data>
                    <value><string>Tic</string></value>
                    <value><string>Tac</string></value>
                    <value><string>Toe</string></value>
                  </data>
                </array>
              </value>
            </member>
          </struct>
        </value>
      </member>
      <member><name>width</name><value><i4>10</i4></value></member>
      <member><name>height</name><value><i4>2</i4></value></member>
    </struct>
    </value>
    </answer>}
    
    parser = XMLRPC::XMLParser::REXMLStreamParser::StreamListener.new
    parser.parse(xml)
    
    puts "Value (accessor): '#{parser.value}'"
    puts "Values (accessor): '#{parser.values}'"
    puts "Value (instance_variable_get): '#{parser.instance_variable_get('@value')}'"
    

    There must be a better way!

    This is the output:

    Value (accessor): ''
    Values (accessor): ''
    Value (instance_variable_get): '{"test"=>"hello", "age"=>12, "requirements"=>{"confirmation"=>["Bread", "Butter"], "document"=>["Tic", "Tac", "Toe"]}, "width"=>10, "height"=>2}'
    

    This makes my eyes hurt.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some XML that I need to parse using SQL Server 2008. I
I have a problem right now, I need to parse an XML but some
I need to parse a XML String so I can use some of the
I need to parse some text in a UITextField and turn it into a
Using Ruby, I'm trying to parse some documentation in which I need to split
I have some sort of recursive function, but I need to parse a string,
I'm very new to python and I need to parse some dirty xml files
I need to parse some XML that triggers an NSURLConnection. After the parsing finished,
I'm no expert in regex but I need to parse some input I have
I need parse some XML and wrote some helpers. I am not expert in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.