在PHP中使用simplexml\u load\u字符串时,在节点中剥离锚标记

在PHP中使用simplexml\u load\u字符串时,在节点中剥离锚标记,php,xml,simplexml,Php,Xml,Simplexml,我试图在使用simplexml\u load\u字符串时获取节点的值。我很好地获得了节点的值,但是由于某种原因,标记中包含的锚标记被完全剥离,并且没有显示出来 以下是xml: <MessageAfterVoting>Thanks for voting! Here is a link to a page: <a href="/poll/result.html" >clickhere</a></MessageAfterVoting> 我这样调用sim

我试图在使用simplexml\u load\u字符串时获取节点的值。我很好地获得了节点的值,但是由于某种原因,标记中包含的锚标记被完全剥离,并且没有显示出来

以下是xml:

<MessageAfterVoting>Thanks for voting! Here is a link to a page: <a href="/poll/result.html" >clickhere</a></MessageAfterVoting>
我这样调用simplexml\u load\u字符串:

$PresentationContent = simplexml_load_string($pollXML);
$xml = simplexml_load_string($pollXML);
$MessageAfterVoting = $xml->MessageAfterVoting;
$PresentationContent = SimpleXmlElementAsString($MessageAfterVoting);

有人有解决办法的想法吗?最好不要使用CDATA?

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

但CDATA是正确的方式。

尝试以下功能:

function SimpleXmlElementAsString($simpleXmlElement)
{           
    $innerXML= '';
    foreach (dom_import_simplexml($simpleXmlElement)->childNodes as $child)
    {
        $innerXML .= $child->ownerDocument->saveXML( $child );
    }
    return $innerXML;
}
所以你可以这样使用它:

$PresentationContent = simplexml_load_string($pollXML);
$xml = simplexml_load_string($pollXML);
$MessageAfterVoting = $xml->MessageAfterVoting;
$PresentationContent = SimpleXmlElementAsString($MessageAfterVoting);