I hope you can help me with that. The XML file looks like this:
<channel><item>
<description>
<div> <a href="http://image.com">
<span>
<img src="http://image.com" />
</span>
</a>
Lorem Ipsum is simply dummy text of the printing etc...
</div>
</description>
</item></channel>
I can get the contents of the description tag, but when i do that, i get the whole structure which has lots of css in there and i don’t want that.
What i really need is to parse the href link and the Lorem Ipsum text only. I’m trying with simple XML, but can’t find out, looks too complicated. Any ideas?
edit:
code i use to parse xml
$file = new SimpleXMLElement($mydata);
{
foreach($file->channel->item as $post)
{
echo $post->description; } }
This is the final code that answears the question.
It is IMSoP’s code and i added the
$text = $description_sxml->xpath('//div');to read the text that is inside the<div>.In my case some of the posts in the xml have multiple
<div>and<span>tags, so to parse all of them i might have to add another->xpathfor the<span>or maybe anif... elsestatement so that if i don’t have any content inside<div>, echo the<span>contents instead.Thanks for your replies.