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

  • Home
  • SEARCH
  • 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 5939017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:46:01+00:00 2026-05-22T15:46:01+00:00

I have a hash that i wanted to parse to XML using SimpleXML but

  • 0

I have a hash that i wanted to parse to XML using SimpleXML but there is a trick I dont know how to handle:

My hash looks like:

require 'xmlsimple'
test = { "subroot" => {
  field1 => {'var1' = ['xyz'], 'var2' = ['yyyy']},
  field2 => {'var1' = ['xyz'], 'var2' = ['yyyy']},
  field3 => {'var1' = ['xyz'], 'var2' = ['yyyy']}, 
  'id' = 'xxxxxx'} }

I parse it to XML using:

XmlSimple.xml_out(teste, 'RootName' => 'root') 

resulting in:

<cenario>
  <subroot id="xxxxxx">
     <field1>
       <var1>xyz</var1>
       <var2>yyyy</var2>
     </field1>
     <field2>
       <var1>xyz</var1>
       <var2>yyyy</var2>
     </field2>
     <field3>
       <var1>xyz</var1>
       <var2>yyyy</var2>
     </field3>
   </subroot>
</cenario>

That’s OK and works like a charm but there is problem when I need to loop.
Im doing a automated test that loops on each test and save the test data on a Hash and by the end of the tests i need to save it on a xml and i need to get something like this:

<cenario>
      <subroot id="xxxxxx">
         <field1>
           <var1>xyz</var1>
           <var2>yyyy</var2>
         </field1>
         <field2>
           <var1>xyz</var1>
           <var2>yyyy</var2>
         </field2>
         <field3>
           <var1>xyz</var1>
           <var2>yyyy</var2>
         </field3>
       </subroot>
      .
      .
      .
      <subroot id="xxxx10x">
         <field1>
           <var1>xyz</var1>
           <var2>yyyy</var2>
         </field1>
         <field2>
           <var1>xyz</var1>
           <var2>yyyy</var2>
         </field2>
         <field3>
           <var1>xyz</var1>
           <var2>yyyy</var2>
         </field3>
       </subroot>
    </cenario>

merging each hash on each test will not do the trick cz it prevents the last hash (subroot)
Did i made myself clear?
Can’t simpleXML do the trick or do I need to look for another solution?

  • 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-05-22T15:46:02+00:00Added an answer on May 22, 2026 at 3:46 pm

    Thks for the help…

    I figured out that i dont need Hash keys if i put a “instance” of the hash inside a array…
    I can use the same Hash name, each array slot saves a instance of my hash than i can call simpleXML or to_xml

    No i just need to figure out how to remove the objects tags that makes the xml bigger.

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

Sidebar

Related Questions

Is there a hash implementation around that doens't remember key values? I have to
I have a bar that shows up (in rails) from a flash hash. I
I'm sure I've seen this before and know the answer to it but after
I have a hash table where the vast majority of accesses at run-time follow
I have 150 32 by 48 matrices of values that represent color intensities from
I have the following piece of JS code within a function that responds to
I have the following piece of JS code within a function that responds to
I'm coding a site that makes heavy use of AJAX to load pages for
I'm trying to figure out whats the best way to get checkboxes to properly

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.