1

我试图在使用 simplexml_load_string 时获取节点的值。我得到节点的值很好,但由于某种原因,标签中包含的锚标签被完全剥离,并且没有显示出来。

这是xml:

<MessageAfterVoting>Thanks for voting! Here is a link to a page: <a href="/poll/result.html" >clickhere</a></MessageAfterVoting>

当我使用 simplexml_load_string 访问此节点时(MessageAfterVoting)。我只得到文字

Thanks for voting! Here is a link to a page: 

我这样调用 simplexml_load_string :

$PresentationContent = simplexml_load_string($pollXML);

有人对解决方法有任何想法吗?最好不要使用 CDATA?

4

2 回答 2

1

如果您不能使用 CDATA,那么您可以使用 html 实体。将 < 和 > 更改为 < 和> 代码。

但是 CDATA 是正确的方法。

于 2012-11-23T16:23:10.210 回答
1

试试这个功能:

function SimpleXmlElementAsString($simpleXmlElement)
{           
    $innerXML= '';
    foreach (dom_import_simplexml($simpleXmlElement)->childNodes as $child)
    {
        $innerXML .= $child->ownerDocument->saveXML( $child );
    }
    return $innerXML;
}

所以你会像这样使用它:

$xml = simplexml_load_string($pollXML);
$MessageAfterVoting = $xml->MessageAfterVoting;
$PresentationContent = SimpleXmlElementAsString($MessageAfterVoting);
于 2012-11-23T17:12:01.583 回答