DOMElement类的对象无法转换为字符串

Rap*_*aël 14 php domdocument xml-parsing

我尝试解析XML rss flux.实际上,抛出了一个错误:

Catchable fatal error: Object of class DOMElement could not be converted to string in ...
Run Code Online (Sandbox Code Playgroud)

我想获得标签"link"的值"test"

这是我的代码:

//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;
Run Code Online (Sandbox Code Playgroud)

这是助焊剂:

<?xml version="1.0" encoding="ISO-8859-15" ?>
<rss version="2.0">
    <channel>
        <title>test</title>
        <link>http://test.fr</link>
    </channel>
</rss>
Run Code Online (Sandbox Code Playgroud)

有人可以帮帮我吗?

hak*_*kre 25

$link是一个无法转换为字符串的对象(某些对象可以).

要查看它是哪个对象,请使用var_dump($link);.我假设它是一个DOMElementDocs,请查看它必须提供的所有属性和方法的链接,例如

echo $link->tagName;
Run Code Online (Sandbox Code Playgroud)

要么

echo $link->textContent;
Run Code Online (Sandbox Code Playgroud)