本文整理汇总了PHP中SimpleXMLElement::addCdataChild方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXMLElement::addCdataChild方法的具体用法?PHP SimpleXMLElement::addCdataChild怎么用?PHP SimpleXMLElement::addCdataChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXMLElement
的用法示例。
在下文中一共展示了SimpleXMLElement::addCdataChild方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: asXML
public function asXML()
{
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><item></item>', LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_ERR_FATAL);
if ($this->preferCdata) {
$xml->addCdataChild('title', $this->title);
} else {
$xml->addChild('title', $this->title);
}
$xml->addChild('link', $this->url);
if ($this->preferCdata) {
$xml->addCdataChild('description', $this->description);
} else {
$xml->addChild('description', $this->description);
}
if ($this->contentEncoded) {
$xml->addCdataChild('xmlns:content:encoded', $this->contentEncoded);
}
foreach ($this->categories as $category) {
$element = $xml->addChild('category', $category[0]);
if (isset($category[1])) {
$element->addAttribute('domain', $category[1]);
}
}
if ($this->guid) {
$guid = $xml->addChild('guid', $this->guid);
if ($this->isPermalink === false) {
$guid->addAttribute('isPermaLink', 'false');
}
}
if ($this->pubDate !== null) {
$xml->addChild('pubDate', date(DATE_RSS, $this->pubDate));
}
if (is_array($this->enclosure) && count($this->enclosure) == 3) {
$element = $xml->addChild('enclosure');
$element->addAttribute('url', $this->enclosure['url']);
$element->addAttribute('type', $this->enclosure['type']);
if ($this->enclosure['length']) {
$element->addAttribute('length', $this->enclosure['length']);
}
}
if (!empty($this->author)) {
$xml->addChild('author', $this->author);
}
return $xml;
}