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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:12:50+00:00 2026-06-03T12:12:50+00:00

I have seen several things on this, but nothing has seemed to work so

  • 0

I have seen several things on this, but nothing has seemed to work so far. I am parsing an xml via a url using nokogiri on rails 3 ruby 1.9.2.

A snippet of the xml looks like this:

<NewsLineText>
  <![CDATA[
  Anna Kendrick is ''obsessed'' with 'Game of Thrones' and loves to cook, particularly     creme brulee.
  ]]>
</NewsLineText>

I am trying to parse this out to get the text associated with the NewsLineText

r = node.at_xpath('.//newslinetext') if node.at_xpath('.//newslinetext')
s = node.at_xpath('.//newslinetext').text if node.at_xpath('.//newslinetext')
t = node.at_xpath('.//newslinetext').content if node.at_xpath('.//newslinetext')
puts r
puts s ? if s.blank? 'NOTHING' : s
puts t ? if t.blank? 'NOTHING' : t

What I get in return is

<newslinetext></newslinetext>
NOTHING
NOTHING

So I know my tags are named/spelled correctly to get at the newslinetext data, but the cdata text never shows up.

What do I need to do with nokogiri to get this text?

  • 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-03T12:12:51+00:00Added an answer on June 3, 2026 at 12:12 pm

    You’re trying to parse XML using Nokogiri’s HMTL parser. If node as from the XML parser then r would be nil since XML is case sensitive; your r is not nil so you’re using the HTML parser which is case insensitive.

    Use Nokogiri’s XML parser and you will get things like this:

    >> r = doc.at_xpath('.//NewsLineText')
    => #<Nokogiri::XML::Element:0x8066ad34 name="NewsLineText" children=[#<Nokogiri::XML::Text:0x8066aac8 "\n  ">, #<Nokogiri::XML::CDATA:0x8066a9c4 "\n  Anna Kendrick is ''obsessed'' with 'Game of Thrones' and loves to cook, particularly     creme brulee.\n  ">, #<Nokogiri::XML::Text:0x8066a8d4 "\n">]>
    >> r.text
    => "\n  \n  Anna Kendrick is ''obsessed'' with 'Game of Thrones' and loves to cook, particularly     creme brulee.\n  \n"
    

    and you’ll be able to get at the CDATA through r.text or r.children.

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

Sidebar

Related Questions

I have seen several posts similar to this but none with a strait forward
I have seen several questions with people asking about the same problem but none
(Note: I have seen several questions regarding .NET logging frameworks, but haven't seen any
So, I've seen this type thing on several occasions, but I've never been able
I've recently seen several people doing things like this here on Stackoverflow: class A:
I've recently seen several people doing things like this here on Stackoverflow: class A:
I have seen this question in SO several times. Most of cases user called
I have seen several variations. Suppose I wish my cookie to expire after one
I have seen several places in stackoverflow where folks have elegantly and easily turned
I have seen several sites where these social share buttons looks perfectly horizontal aligned.

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.