What is a simple way to parse this specific xml using php?
Whay is a good way ( native way that w开发者_如何学运维orks in both php 4 and 5 ) to extract the value from this xml string
<root>
<node1>
<![CDATA[THE-TEXT]]>
</node1>
</root>
I wish to extract THE-TEXT content.
you can use simple xml with a third parameter to parse CDATA as Text:
look there: http://www.vijayjoshi.org/2009/09/22/quick-php-tip-how-to-parse-cdata-sections-using-simplexml/
Maybe something like this:
$dom = new DOMDocument();
$dom->loadXML($xml);
$descriptions = $dom->getElementsByTagName('node1');
foreach($descriptions as $desc)
{
echo "<div>".$desc->textContent."</div>";
}
精彩评论