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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:54:23+00:00 2026-05-30T21:54:23+00:00

I have this script that is a part of a bigger one. I have

  • 0

I have this script that is a part of a bigger one. I have tree diffrent XML files that looks a litle diffrent from each other and I need some type of control structure to handle nil-object and xpath expressions better

The script that I have right now, outputs nil objects:

require 'open-uri'
require 'rexml/document'
include REXML

@urls = Array.new()
@urls << "http://testnavet.skolverket.se/SusaNavExport/EmilObjectExporter?id=186956355&amp;strId=info.uh.kau.KTADY1&amp;EMILVersion=1.1"
@urls << "http://testnavet.skolverket.se/SusaNavExport/EmilObjectExporter?id=184594606&amp;strId=info.uh.gu.GS5&amp;EMILVersion=1.1"
@urls << "http://testnavet.skolverket.se/SusaNavExport/EmilObjectExporter?id=185978100&amp;strId=info.uh.su.ARO720&amp;EMILVersion=1.1"

@urls.each do |url|
  doc = REXML::Document.new(open(url).read)
  doc.elements.each("/educationInfo/extensionInfo/nya:textualDescription/nya:textualDescriptionPhrase | /ns:educationInfo/ns:extensionInfo/gu:guInfoExtensions/gu:guSubject/gu:descriptions/gu:description | //*[name()='ct:text']"){
      |e| m = e.text 
      m.gsub!(/<.+?>/, "")
      puts "Description: " + m 
      puts ""   
    }
end

OUTPUT:

Description: bestrykning, kalandrering, tryckning, kemiteknik

Description: Vill du jobba med internationella och globala frågor med…
Description: The study of globalisation is becoming ever more
important for our understanding of today´s world and the School of
Global Studies is a unique environment for research.

Description:

Description:

Description: Kursen behandlar identifieringen och beskrivningen av
sjukliga förändringar i mänskliga skelett. Kursen ger en
ämneshistorisk bakgrund och skelettförändringars förhållanden till
moderna kliniska data diskuteras.

  • 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-30T21:54:25+00:00Added an answer on May 30, 2026 at 9:54 pm

    See this post on how to skip over entries when using a block in ruby. The method each() on doc.elements is being called with a block (which is you code containing gsub and puts calls). The “next” keyword will let you stop executing the block for the current element and move on to the next one.

    
    doc.elements.each("/educationInfo/extensionInfo/nya:textualDescription/nya:textualDescriptionPhrase | /ns:educationInfo/ns:extensionInfo/gu:guInfoExtensions/gu:guSubject/gu:descriptions/gu:description | //*[name()='ct:text']"){
          |e| m = e.text 
          m.gsub!(//, "")
    
          next if m.empty?
    
          puts "Description: " + m 
          puts ""   
        }
    

    We know that “m” is a string (and not nil) when using the “next” keyword because we just called gsub! on it, which did not throw an error when executing that line. That means the blank Descriptions are caused by empty strings, not nil objects.

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

Sidebar

Related Questions

I have this code (part of bigger script): flashvars.xmlSource = datasource.xml; datasource.xml looks like:
I have this little script that shows one wisdom each day. so I have
I have this action script that pulls images from a xml file > myPhoto
I have part of my script that goes like this: while read line do
I have this script that collects data from users and I want to check
I have this script, that does several operations on some files, which then creates
I have this SQL change script that runs as part of my nant orchestrated
I have a really simple build script that looks like this: <Project xmlns=http://schemas.microsoft.com/developer/msbuild/2003 ToolsVersion=4.0
I have this script that run to fix my menu bar to the browser
I have this script that works, but I need to change the format of

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.