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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:09:39+00:00 2026-05-12T08:09:39+00:00

I have a little problem that I can’t figure out how to solve. I

  • 0

I have a little problem that I can’t figure out how to solve.
I have an XML (actually it’s RSS) file that I’m trying to parse with PHP, but the CDATA tag come out blank.

Here’s the XML Code
and here’s the PHP file

Everything works fine, except that the description tag is not printing.
I would be very grateful if some one could help.

  • 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-12T08:09:39+00:00Added an answer on May 12, 2026 at 8:09 am

    Just out of curiosity, after getting your XML (I hope I didnt’t destroy it in the process — I’ll see if I can edit the OP to correct it) :

    • did you cast the description to a string ?

    What I mean is you could use this :

    $xml = simplexml_load_string($str);
    foreach ($xml->channel->item as $item) {
        var_dump($item->description);
    }
    

    But it would only get you that :

    object(SimpleXMLElement)[5]
    object(SimpleXMLElement)[3]
    

    Which is not that nice…

    You need to cast the data to string, like this :

    $xml = simplexml_load_string($str);
    foreach ($xml->channel->item as $item) {
        var_dump((string)$item->description);
    }
    

    And you get the descriptions :

    string '
    
    This is one of the content that I need printed on the screen, but nothing is happening. Please, please...output something... <br /><br /> <b>Showing</b>: 2 weeks<br /> <b>Starting On</b>: August 7, 2009 <br /> <b>Posted On</b>: August 7, 2009 <br />
    <a href="http://www.mysite.com">click to view</a> 
                ' (length=329)
    
    string '
    
    Another content...This is another of the content that I need printed on the screen, but nothing is happening. Please, please...output something... <br /><br /> <b>Showing</b>: 2 weeks<br /> Starting On: August 7, 2009 <br /> <b>Posted On</b>: August 7, 2009
    ; 
                   ' (length=303)
    

    (Using trim on those might prove useful, btw, if you XML is indented)

    Else… Well, we’ll probably need your php code (at least, would be useful to know how you are getting to the description tag 😉 )


    EDIT

    Thanks for the reformated XML !

    If I go to pastebin, in the textarea at the bottom of the page, there is a white space at the beginning of the XML, before the <?xml version="1.0" encoding="utf-8"?>

    If you have that one in your real XML data, it will be a source of problem : it is not valid XMl (the XML declaration has to be the first thing in the XML data).

    You’ll get errors like this one :

    Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : XML declaration allowed only at the start of the document
    

    Can you check that ?

    And, if the problem is here, you should activate error_reporting and display_errors 😉 That would help !


    EDIT after taking a look at the PHP file :

    In your for loop, you are doing this to get your description data :

    $item_desc = $x->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;
    

    description doesn’t contain any childNode, I’d say ; what about using it’s nodeValue directly ?

    Like this :

    $item_desc = $x->item($i)->getElementsByTagName('description')->item(0)->nodeValue;
    

    It seems to be working better this way 🙂

    As a sidenote, you could probably do the same for other tags, I suppose ; for instance, this seems to be working too :

    $item_title=$x->item($i)->getElementsByTagName('title')->item(0)->nodeValue;
    $item_link=$x->item($i)->getElementsByTagName('link')->item(0)->nodeValue;
    

    What does this give you ?


    Another EDIT : and here is the code I would probably use :

    $xmlDoc = new DOMDocument();
    $xmlDoc->loadXML($str);         // I changed that because I have the XML data in a string
    
    //get elements from "<channel>"
    $channel = $xmlDoc->getElementsByTagName('channel')->item(0);
    $channel_title = $channel->getElementsByTagName('title')->item(0)->nodeValue;
    $channel_link = $channel->getElementsByTagName('link')->item(0)->nodeValue;
    $channel_desc = $channel->getElementsByTagName('description')->item(0)->nodeValue;
    
    //output elements from "<channel>"
    echo "<p><a href='" . $channel_link . "'>" . $channel_title . "</a>";
    echo "<br />";
    echo $channel_desc . "</p>";
    
    //get and output "<item>" elements
    $x = $xmlDoc->getElementsByTagName('item');
    for ($i=0 ; $i<=1 ; $i++) {
        $item_title = $x->item($i)->getElementsByTagName('title')->item(0)->nodeValue;
        $item_link = $x->item($i)->getElementsByTagName('link')->item(0)->nodeValue;
        $item_desc = $x->item($i)->getElementsByTagName('description')->item(0)->nodeValue;
        echo ("<p><a href='" . $item_link
        . "'>" . $item_title . "</a>");
        echo ("<br />");
        echo ($item_desc . "</p>");
        echo' <p />';
    }
    

    Note I have the XML data in a string, and I don’t need to fetch it from an URL, so I’m using the loadXML method and not load.

    The major difference is that I removed some childNodes accesses, that I feel were not necessary.

    Does this seem OK to you ?

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

Sidebar

Related Questions

I have a little newbie problem that I cannot figure out, I am having
I have this little problem, that I cannot figure out which arguments to pass
I have a problem that I can't figure out myself. I've tried using LEFT
I have a little problem and I'm hopping that you can help me solve
I have a problem that i can't solve, i have a little application that
I have a little problem with autoconf, I know that you can use configure.ac
I ran into a little problem today that I can't seem to solve in
I have a little problem, I'm trying to input some data that I get
I have a little problem and hope that you can help me. I want
I have a little problem that perhaps you can help me with. I try

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.