How to get images in XML CDATA and DESCRIPTION

1

I have some xml files, and several of them news images are inside the description, in one of them the image is inside the CDATA, at the time I return the array a description does not appear any element according to the photo: p>

InanothercasetheimageisalreadyinsertedinsidethedescriptionthatdoesnotcontainaCDATAlikeintheimagebelow:

In both cases I can not find a way to manipulate these images any way I want, I wanted to know if they could help me,

I'll post my code here too, for now it's simple I'm still developing it, and I can not get out of that part.

 $feedwwf = file_get_contents('https://www.wwf.org.br/rss/rss.cfm?B5ABCD22- 
A9C2-3BB4-44189EF9064E5481',LIBXML_NOCDATA);    
 $rsswwf = new SimpleXMLElement($feedwwf);
  $wwf = $rsswwf->channel->item[0];
  $desc = $wwf->description;


$feedg1 = file_get_contents('http://pox.globo.com/rss/g1/');
$rssg1 = new SimpleXMLElement($feedg1);
$g1 = $rssg1->channel->item[0];
$desc = $g1->description->attributes('img') ;
    
asked by anonymous 30.07.2018 / 02:33

1 answer

2

PHP Provides a comprehensive class to handle XML DOMDocument

[ link ]

You can manipulate the document as follows:

$dom = new DOMDocument();
$dom->load('http://pox.globo.com/rss/g1/');

# localizando um elemento dentro do xml
$url = $dom->getElementsByTagName('url');

# alterando o primeiro item ou seja o primeiro elemento
$url->item(0)->nodeValue = 'imagem_teste.png';

$dom->saveXML();
    
31.07.2018 / 03:06