PHPに。simpleXMLという、XMLパーサがあるです。
You can't use CDATA with SimpleXML, but there is a way around it. Wrap your child in CDATA like this:
ぱぁどん?
You can't use CDATA with SimpleXML,
あんだってをい?
いやまぁ「回避策」はいくつか、上述Pageに載ってるわけなのですが。
<? $listing->addChild( 'description', '<![CDATA[' . $row['description'] . ']]>' ); ?> And then when you display the XML, run it through this function: <? function fixCDATA($string) { $find[] = '<![CDATA['; $replace[] = '<![CDATA['; $find[] = ']]>'; $replace[] = ']]>'; return $string = str_replace($find, $replace, $string); } $xml = fixCDATA( $xml->asXML() ); echo $xml;
とか
<?php $str = <<< XML <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <menu> <item> <title><![CDATA[Café]]></title> <description><![CDATA[Some description.]]></description> </item> </menu> XML; $str = preg_replace("/\<\!\[CDATA\[(.*?)\]\]\>/ies", "'[CDATA]'.base64_encode('$1').'[/CDATA]'", $str); $xml = new SimpleXMLElement($str); // Return item title's foreach ($xml->item as $item) { $tmp = (string) $item->title; $tmp = preg_replace("/\[CDATA\](.*?)\[\/CDATA\]/ies", "base64_decode('$1')", $tmp); echo $tmp; }
とか。
でもさぁ。でもさぁ。………いやまぁうんいいや orz