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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:53:08+00:00 2026-06-16T18:53:08+00:00

Reference page The XML is embedded under the <pre> tag of the returned HTML

  • 0

Reference page

The XML is embedded under the <pre> tag of the returned HTML page.
I can extract the contents of the <pre> tag, but I am unable to convert this to XML correctly.
I tried using the to_xml method of the NodeSet class, but it seems that the line endings (\n) are messing up the parsing.

Here is a snippet of my code:

url = "http://www.ncbi.nlm.nih.gov/pubmed/?term=NS044283[GR]&dispmax=200&report=xml"
doc = Nokogiri::XML(open(url))
pre = doc.xpath('//pre')
xml = pre.to_xml
contents = Nokogiri::XML(xml)
articles = contents.xpath('\\PubmedArticle')
(article = [])
  • 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-16T18:53:09+00:00Added an answer on June 16, 2026 at 6:53 pm

    Since you’re going to use Nokogiri to parse it anyway, just call content instead of to_xml:

    require 'nokogiri'
    require 'open-uri'
    url = "http://www.ncbi.nlm.nih.gov/pubmed/?term=NS044283[GR]&dispmax=200&report=xml"
    doc = Nokogiri::XML(open(url))
    pre = doc.xpath('//pre')
    xml = "<root>" + pre.text + "</root>"
    contents = Nokogiri::XML(xml)
    articles = contents.css('PubmedArticle')
    puts contents.css('ArticleTitle').map{|x| x.content}.count   
    => 25
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my theme I already use (in local.xml): <reference name=top.links> <action method=setTemplate><template>page/html/header/links.phtml</template></action> </reference> Now
On the developer page (http://developers.facebook.com/docs/reference/plugins/comments/) I can see that the facebook comment Social plugin
I know I can put something in the web.xml like this <error-page> <exception-type>java.lang.Throwable</exception-type> <location>/error.jsp</location>
page.xml contains: <default translate=label module=page> <label>All Pages</label> <reference name=root> <action method=addBodyClass><className>testing</className></action> </reference> Yet it's
I’ve created a menu in page.xml and it looks like this: <reference name=primary.menu> <action
I couldn't find any information in the reference page of MPMoviePlayerController or in the
I reference the current page in a class with Page page = HttpContext.Current.CurrentHandler as
The Verilog Golden Reference Guide on page 12 warns against unsynthesisable always blocks, and
Reading the MCIMX50 Application Processor Reference Manuals on page 1368 (Section 33.3) there is
I am trying to reference the jQuery library in my master page like so:

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.