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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:19:19+00:00 2026-06-02T04:19:19+00:00

Taking the BBC News RSS feed for example, one of their news items is

  • 0

Taking the BBC News RSS feed for example, one of their news items is as follows:

<item><title>Pupils 'bullied on sports field'</title><description>bla bla..

I have some java code parsing this – however, when a title contains an apostrophe (as above), the parsing stops, so I end up with the following title: Pupils ‘ and then it continues on and parses the description (which is fine). How do I get it to parse the full title? The following is a segment of code from inside my for loop where I parse the info:

                    NodeList title = element.getElementsByTagName("title");
                    Element line = (Element) title.item(0);
                    tmp.setTitle(getCharacterDataFromElement(line).toString());

The exact same code is used to parse the other elements like description and pubDate etc, which are all fine.

This is the getCharacterDataFromElement method:

public static String getCharacterDataFromElement(Element e) {
    Node child = ((Node) e).getFirstChild();
    if (child instanceof CharacterData) {
        CharacterData cd = (CharacterData) child;
        return cd.getData();
    }
    return "";
}

What am I doing wrong? I use the DocumentBuilder, DocumentBuilderFactory and org.w3c.dom to work with the RSS Feed.

  • 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-02T04:19:20+00:00Added an answer on June 2, 2026 at 4:19 am

    As davidfrancis suggested, you should iterate over all children in getCharacterDataFromElement().

    Alternatively, if you can use DOM level 3, you can use the Node.getTextContent() method instead which does what you want.

    NodeList title = element.getElementsByTagName("title");
    Element line = (Element)title.item(0);
    tmp.setTitle(line.getTextContent());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Taking this file as an example, I'm trying to read the data in a
Taking the jQuery framework for example, if you run code like this: $(document).ready(function init()
Taking the GNU make application as an example, when I create a makefile it
Taking Ryan Bates' asciicast as an example: http://asciicasts.com/episodes/163-self-referential-association He ends with two associations of
Taking an example that is provided on the Fluent nHibernate website, I need to
Taking the W3C vehicle XSD as an example: <schema xmlns=http://www.w3.org/2001/XMLSchema targetNamespace=http://cars.example.com/schema xmlns:target=http://cars.example.com/schema> <complexType name=Vehicle
Taking the following snippet as an example: struct Foo { typedef int type; };
Taking this simplifed example of my XML: <?xml version=1.0?> <message xmlns=http://www.mydomain.com/MyDataFeed xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://www.mydomain.com/MyDataFeed https://secure.mydomain/MyDataFeed/myDataFeed.xsd
Taking into account that some Windows Installer products from independent vendors (for example IstallShield)
Taking the Stack Overflow tagging system as the canonical example, how can I get

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.