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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:17:59+00:00 2026-05-23T11:17:59+00:00

I am trying to evaluate 4 XML files that I create from a mysql

  • 0

I am trying to evaluate 4 XML files that I create from a mysql database, I want to output the text of those XML field as a pairs of data so I can create a hash. (Ex: “Total Builds, 359”) I am pretty sure I am getting a syntax error because of the way I am using the block

Here is what I am trying to do:

  while i < numberOfFiles do
            #create a document
            doc = Document.new(File.new(filenames[i]))
            doc.elements.each("//row/field")
            {
             |e|  ##Syntax error here
             name = e.attributes['name']
             text = e.text
             if name == "Total Builds"
                    puts name + ", " + text
             elsif name == "Successful Builds"
                    puts name + ", " + text
             elsif name == "Failed Builds"
                    puts name + ", " + text
             else
                    puts text.join(",")
             end
            }

I know that the format of this block is wrong, but is there a way to do something similar to this in ruby?

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-23T11:17:59+00:00Added an answer on May 23, 2026 at 11:17 am

    I don’t see why it would cause a syntax error but you are mixing do end and curly braces. I recommend that you don’t, at least not for such a long block.

    Try something like

    doc.elements.each("//row/field") do |element|
      name = element.attributes['name']
      text = element.text
      builds = ["Total Builds", "Successful Builds", "Failed Builds"]
      if builds.include?(name)
        puts name + ", " + text
      else
        puts text.join(",")
      end
    end
    

    Also, while statements like that are not how it’s usually done in Ruby. Often it’s something like:

    filenames.each do |filename|
      doc = Document.new(File.new(filename))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to evaluate an xml node using xpath and i'm not sure why
I am trying to evaluate the following from a string boolean value = evaluate(false
I'm trying to get an attribute id ( fileID ) from my XML document
I am trying to get an attribute value from an XML file, but my
I'm trying to parse some XML from the USGS. Here's an example The parameterCd
I'm trying to create a function in Groovy that does the following: Accepts 2
I am trying to evaluate a function in a new context, ie, one that
I am trying to load an XML file, and then evaluate 2 different specific
Ive been trying to pull data from an xml file but i keep getting
I have a large (1MB+) XML file, and I'm trying to create an object

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.