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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:32:34+00:00 2026-05-25T11:32:34+00:00

I am using libxml-ruby gem to read a xml string. I am unable to

  • 0

I am using libxml-ruby gem to read a xml string.

I am unable to extract the required info from xml string.

Currently i have following xml

<?xml version="1.0" encoding="utf-8"?>
<message>
  <head>
    <api_key>252f5df2df522fg5fd25df2df5df2fd5</api_key>
    <user>123</user>
    <secret>********************</secret>
    <signature>****************</signature>
    <synchronization token="kj0s09ew090mv904v09409905b" last_synchronize_on="2010-01-02 11:30" />
  </head>
  <blockings>
    <blocking token="AAA" start_time="2010-01-01 10:00" end_time="2010-01-01 12:00" method="REQUEST" is_forced="FALSE" />
    <blocking token="BBB" start_time="2010-01-03 15:00" end_time="2010-01-03 18:00" method="REQUEST" is_forced="FALSE" />
  </blockings>
</message>

How do i get api_key, synchronization token, last_synchronize_on values from this xml string?

How do i get the info of the blocking nodes inside blockings node of this string?

Thanks

  • 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-25T11:32:34+00:00Added an answer on May 25, 2026 at 11:32 am

    You’d use LibXML::XML::Parser to get a LibXML::XML::Document:

    p = LibXML::XML::Parser.file(xml_file)
    # or p = LibXML::XML::Parser.string(xml_string)
    doc = p.parse
    

    Then use find and a bit of XPath to find your nodes:

    api_key_node = doc.find('//api_key').first
    

    That gives you a LibXML::XML::Node in api_key_node so you can call content to get what you want:

    api_key = api_key_node.content
    # "252f5df2df522fg5fd25df2df5df2fd5"
    

    Similar things apply to synchronization but you’d use [] to access the attribute values:

    sync      = doc.find('//synchronization').first
    token     = sync['token']
    last_sync = sync['last_syncrhonize_on']
    

    Same deal again for the <blocking> nodes but you’d iterate through them with each instead of using first.

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

Sidebar

Related Questions

I am trying to read tags from XML using LibXML. I can print all
I have the following in an XML Document: <ul class=toggle-control toggle-retain-state> I'm using XML::LibXML
hi all I'm trying to extract the META description from a webpage using libxml
I create the following XML file, by perl script (Showing down) , using XML::LibXML:
From http://metacpan.org/pod/XML::LibXML::Node : find evaluates the XPath 1.0 expression using the current node as
i have soap based Xml using that soap message i want to perform libxml
I need to create XML in Perl. From what I read, XML::LibXML is great
I am using libxml-ruby for parsing XML. I can able to create the xml
Where does one access the data from a parsed xml file when using libxml?
I am writing an xml exporter in ruby and I am using libxml package

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.