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.
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) :
What I mean is you could use this :
But it would only get you that :
Which is not that nice…
You need to cast the data to string, like this :
And you get the descriptions :
(Using
trimon 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
descriptiontag 😉 )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 :
Can you check that ?
And, if the problem is here, you should activate
error_reportinganddisplay_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 :
description doesn’t contain any childNode, I’d say ; what about using it’s nodeValue directly ?
Like this :
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 :
What does this give you ?
Another EDIT : and here is the code I would probably use :
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
loadXMLmethod and notload.The major difference is that I removed some childNodes accesses, that I feel were not necessary.
Does this seem OK to you ?