You are here

class RSSSimpleXMLElement in Facebook Instant Articles 7

Same name and namespace in other branches
  1. 7.2 modules/fb_instant_articles_rss/src/RSSSimpleXMLElement.php \Drupal\fb_instant_articles_rss\RSSSimpleXMLElement

Extension for SimpleXMLElement.

Class RSSSimpleXMLElement @package Drupal\fb_instant_articles_rss

Hierarchy

  • class \Drupal\fb_instant_articles_rss\RSSSimpleXMLElement extends \Drupal\fb_instant_articles_rss\SimpleXMLElement

Expanded class hierarchy of RSSSimpleXMLElement

File

modules/fb_instant_articles_rss/src/RSSSimpleXMLElement.php, line 16
Contains \Drupal\fb_instant_articles_rss\RSSSimpleXMLElement.

Namespace

Drupal\fb_instant_articles_rss
View source
class RSSSimpleXMLElement extends \SimpleXMLElement {

  /**
   * Adds CDATA text in a node.
   *
   * @param string $cdata_text
   *   The CDATA value to add.
   */
  private function addCdata($cdata_text) {
    $node = dom_import_simplexml($this);
    if (($no = $node->ownerDocument) && is_string($cdata_text)) {
      $node
        ->appendChild($no
        ->createCDATASection($cdata_text));
    }
  }

  /**
   * Creates a child with CDATA value.
   *
   * @param string $name
   *   The name of the child element to add.
   * @param string $cdata_text
   *   The CDATA value of the child element.
   *
   * @return object
   *   The child element.
   */
  public function addChildCdata($name, $cdata_text) {
    $child = $this
      ->addChild($name);
    $child
      ->addCdata($cdata_text);
    return $child;
  }

  /**
   * Adds SimpleXMLElement code into a SimpleXMLElement.
   *
   * @param \SimpleXMLElement $append
   *   XMLElement to append to.
   */
  public function appendXml(\SimpleXMLElement $append) {
    if ($append) {
      if (strlen(trim((string) $append)) == 0) {
        $xml = $this
          ->addChild($append
          ->getName());
        foreach ($append
          ->children() as $child) {
          $xml
            ->appendXml($child);
        }
      }
      else {
        $xml = $this
          ->addChild($append
          ->getName(), (string) $append);
      }
      foreach ($append
        ->attributes() as $n => $v) {
        $xml
          ->addAttribute($n, $v);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RSSSimpleXMLElement::addCdata private function Adds CDATA text in a node.
RSSSimpleXMLElement::addChildCdata public function Creates a child with CDATA value.
RSSSimpleXMLElement::appendXml public function Adds SimpleXMLElement code into a SimpleXMLElement.