2011-10-04 19 views
14

Provo ad analizzare un flusso di rss XML. In realtà, viene generato un errore:Oggetto della classe DOMElement non può essere convertito in stringa

Catchable fatal error: Object of class DOMElement could not be converted to string in ... 

voglio ottenere il valore "test" del "link" tag

Ecco il mio codice:

//check if url contents xml 
      $content = file_get_contents($flux); 

      $xml = new DOMDocument; 
      $xml->loadXML($content); 

      //get the link 
      $link = $xml->getElementsByTagName('link')->item(0); 

      echo $link; 

Ecco il flusso:

<?xml version="1.0" encoding="ISO-8859-15" ?> 
<rss version="2.0"> 
    <channel> 
     <title>test</title> 
     <link>http://test.fr</link> 
    </channel> 
</rss> 

Chiunque può aiutarmi?

+0

aiuto possibile: http://stackoverflow.com/questions/548744/php-xpath-question – diEcho

risposta

21

$link è un oggetto che non può essere convertito in stringa (some objects can).

Per vedere quale oggetto è, utilizzare var_dump($link);. Presumo che sia un DOMElementDocs, vedi il link per tutte le proprietà e i metodi che ha da offrire, ad es.

echo $link->tagName; 

o

echo $link->textContent; 
+0

tagName ritorna "link" non "test". Grazie comunque –

+0

sì, era textContent, grazie mille =) –

Problemi correlati