/**
  * @param string $name
  * @param string $value
  * @param string $namespace
  * @return XMLElement
  */
 public function addChild($name, $value = null, $namespace = null)
 {
     if ($value !== null and is_string($value) === true) {
         $value = str_replace('&', '&', $value);
     }
     return parent::addChild($name, $value, $namespace);
 }
예제 #2
0
 /**
  * Return XML object
  * @return SimpleXMLElement
  */
 public function asXML()
 {
     $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><channel></channel>', LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_ERR_FATAL);
     $xml->addChild('title', $this->title);
     $xml->addChild('link', $this->url);
     $xml->addChild('description', $this->description);
     if ($this->language !== null) {
         $xml->addChild('language', $this->language);
     }
     if ($this->updatePeriod) {
         $xml->addChild("xmlns:sy:updatePeriod", $this->updatePeriod);
     }
     if ($this->updateFrequency) {
         $xml->addChild("xmlns:sy:updateFrequency", $this->updateFrequency);
     }
     if ($this->copyright !== null) {
         $xml->addChild('copyright', $this->copyright);
     }
     if ($this->pubDate !== null) {
         $xml->addChild('pubDate', date(DATE_RSS, $this->pubDate));
     }
     if ($this->lastBuildDate !== null) {
         $xml->addChild('lastBuildDate', date(DATE_RSS, $this->lastBuildDate));
     }
     if ($this->ttl !== null) {
         $xml->addChild('ttl', $this->ttl);
     }
     foreach ($this->items as $item) {
         $toDom = dom_import_simplexml($xml);
         $fromDom = dom_import_simplexml($item->asXML());
         $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true));
     }
     return $xml;
 }
예제 #3
0
 /**
  * Return XML object
  * @return SimpleXMLElement
  */
 public function asXML()
 {
     $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><item></item>', LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_ERR_FATAL);
     $xml->addChild('title', $this->title);
     $xml->addChild('link', $this->url);
     if ($this->pubDate !== null) {
         $xml->addChild('pubDate', date(DATE_RSS, $this->pubDate));
     }
     if ($this->creator) {
         $xml->addChildCData("xmlns:dc:creator", $this->creator);
     }
     if ($this->guid) {
         $guid = $xml->addChild('guid', $this->guid);
         if ($this->isPermalink) {
             $guid->addAttribute('isPermaLink', 'true');
         }
     }
     foreach ($this->categories as $category) {
         $element = $xml->addChild('category', $category[0]);
         if (isset($category[1])) {
             $element->addAttribute('domain', $category[1]);
         }
     }
     $xml->addChild('description', $this->description);
     $xml->addChildCData('xmlns:content:encoded', $this->content);
     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']);
         }
     }
     return $xml;
 }