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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:06:48+00:00 2026-05-14T00:06:48+00:00

Hi i have a yaml file like so — data: – date: 2004-06-11 description:

  • 0

Hi i have a yaml file like so

---
data:
  - date: "2004-06-11"
    description: First description

  - date: "2008-01-12"
    description: Another descripion

How can i do a “ypath” query similar to xpath for xml ? Something like “get the description where the date is 2004-06-11”

YAML.parse_file('myfile.yml').select('/data/*/date == 2004-06-11')

How do you do it, and if that’s possible how can i similarly edit the description by ‘ypath’ ?

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-14T00:06:48+00:00Added an answer on May 14, 2026 at 12:06 am

    The yaml file describes a hash mapping from strings to arrays of hashes that map from strings to strings. There is no such thing as xpath for nested hashes (at least not in the standard library), but it’s simple enough with standard Hash and Enumerable methods:

    hash = YAML.load_file('myfile.yml')
    item = hash["data"].find {|inner_hash| inner_hash["date"] == "2004-06-11"}
    #=> {"date"=>"2004-06-11", "description"=>"First description"}
    

    To change the description, you can then simply do item["description"] = "new description" and then serialize the hash back to YAML using hash.to_yaml.

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

Sidebar

Related Questions

I have a yaml file which looks like this: --- date: 25-01-2010 version: 0.1
I have a YAML formatted text file, and would like to define custom folding
I have a YAML file of groups that I would like to get into
I have a yaml file that looks like this: # The following key opens
As title says, I have a yaml file with values like development: email:dev@abc.com test:
I have the following data in a yaml file - --- - :Subject_list Subject
I have a column in a table defined as following in my yaml file:
I would like to read a thin YAML file using a simple C program.
I would like to know how to parse a YAML file with the following
So I have a yaml file that I'm using as a config file. I'm

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.