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 8082741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:13:11+00:00 2026-06-05T17:13:11+00:00

The xml I want to deal with is like this (from an dict api).

  • 0

The xml I want to deal with is like this (from an dict api). It gives me back a xml file. So I want to get a solution from this xml.

<?xml version="1.0" encoding="UTF-8"?>
<dict num="219" id="219" name="219">
    <key>renown</key>
    <ps>riˈnaun</ps>
    <pron>http://res.iciba.com/resource/amp3/0/0/d5/7a/d57a74f04be82105a2e51d1bed71a667.mp3</pron>
    <ps>rɪˈnaʊn</ps>
    <pron>http://res.iciba.com/resource/amp3/1/0/d5/7a/d57a74f04be82105a2e51d1bed71a667.mp3</pron>
    <pos>n.</pos>
    <acceptation>名望,声誉;</acceptation>
    <sent>
        <orig>
            His renown has spread throughout the country.
        </orig>
        <trans>
            他的名声已传遍全国。
        </trans>
    </sent>
    <sent>
        <orig>
            It's just these heart-thrilling chapters that brought his work world renown.
        </orig>
        <trans>
            正因这些扣人心弦的篇章才使得他的作品举世闻名。
        </trans>
    </sent>
</dict>

I deal with this xml like this way

require 'rexml/document' 
include REXML 
def parse  
    doc = Document.new(@result)  
    doc.elements.each("dict/key") { |e| puts e.text }  
    doc.elements.each("dict/ps") { |e| puts "[" + e.text + "]" }  
    pos_array = Array.new()  
    doc.elements.each("dict/pos") { |e| pos_array.push(e.text) }  
    acc_array = Array.new()  
    doc.elements.each("dict/acceptation") { |e| acc_array.push(e.text) }  
    pos_array.each_index { |i| puts pos_array[i] + " " + acc_array[i] }  
    pos_array.clear  
    doc.elements.each("dict/sent/orig") { |e| pos_array.push(e.text) }  
    acc_array.clear  
    doc.elements.each("dict/sent/trans") { |e| acc_array.push(e.text) }  
    pos_array.each_index { |i| puts "例句" + (i+1).to_s + ":" + pos_array[i] + " " + acc_array[i] }  
  end  

I want a short solution,any short sloution?

  • 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-05T17:13:12+00:00Added an answer on June 5, 2026 at 5:13 pm

    You can use gem xml-simple

    server_config = XmlSimple.xml_in(server_config_path,
                                 {'keyAttr' => 'name', 'ForceArray' => false})
    

    Will return hash with xml structure.

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

Sidebar

Related Questions

I'm trying to parse this XML I want to get a list of all
This is my Xml file.i want to transform this xml file into another customized
I want to parse an XML file using SAX parser in java with this
I want these XML values read from the web service to a TextBlock ,
I want to create a Button otherthan creating it from xml layout.i want to
NOT USING A XML PARSER I want to get the contents of the XML
I need to read data from an xml file that is under the WAR
I've got an XML doc to deal with that contains attributes like: <action name=foo
I have by example following XML: string xml = @<plist version='1.0'> <dict> <key>DataType</key> <string>Employee</string>
Currently my program reads images and text in a record from an xml file,

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.