Example #1
0
 /**
  * Gets line number for where the node is defined.
  *
  * The method `DOMNode::getLineNo()` does not return the correct line number for comment nodes. So this method
  * can return either the original line number returned by libxml or the fixed and correct line number
  * created by the `XMLDocument::fixLineNumbers()` method.
  *
  * @return int Either the original line number returned by libxml or the fixed and correct line number
  * created by the `XMLDocument::fixLineNumbers()` method.
  */
 public function getLineNo()
 {
     $container = $this->ownerDocument->getLineNumberContainer();
     if ($container && $container->contains($this)) {
         return $container->offsetGet($this);
     }
     return parent::getLineNo();
 }
 /**
  * Create a new IE conditional comment
  *
  * @param int    $version  [description]
  * @param string $operator [description]
  * @param bool   $negate   [description]
  * @param string $content  [description]
  */
 public function __construct($version = self::DEFAULT_VERSION, $operator = self::DEFAULT_OPERATOR, $negate = false, $content = null)
 {
     parent::__construct();
     if (is_string($content) or $content instanceof \shgysk8zer0\Core_API\Interfaces\toString) {
         $this->content = "{$content}";
     } elseif ($content instanceof \DOMElement) {
         if (is_null($content->ownerDocument)) {
             (new \DOMDocument())->appendChild($content);
         }
         $this->content = $content->ownerDocument->saveHTML($content);
     }
     if (is_int($version)) {
         $this->version = $version;
     }
     if (is_bool($negate)) {
         $this->negate = $negate;
     }
     if (is_string($operator) and in_array($operator, $this->_operators)) {
         $this->operator = $operator;
     }
     $this->appendData($this->_getCondition() . $this->content);
 }
Example #3
0
$node->appendChild($charnode);
/* DOMComment */
$comment = new DOMComment('Testing character data and extending nodes');
$charnode->appendChild($comment);
echo "Comment Length: " . $comment->length . "\n";
$comment->data = 'Updated comment';
echo "New Comment Length: " . $comment->length . "\n";
echo "New Comment Data: " . $comment->data . "\n";
/* DOMCDataSection */
$cdata = new DOMCDataSection('Chars: <>&"');
$charnode->appendChild($cdata);
echo "Substring: " . $cdata->substringData(7, 4) . "\n";
$cdata->replaceData(10, 1, "'");
echo "New Substring: " . $cdata->substringData(7, 4) . "\n";
/* DOMCharacterData using DOMComment */
$comment = new DOMComment('instructions');
echo "Comment Value: " . $comment->data . "\n";
$comment->data = 'some more instructions';
echo "New Comment Value: " . $comment->data . "\n";
$comment->insertData(10, 'pi ');
$comment->replaceData(18, 5, 'i');
$comment->insertData(20, 'g');
$comment->deleteData(13, 2);
$comment->deleteData(10, 3);
$comment->insertData(10, 'comment ');
echo "Updated Comment Value: " . $comment->data . "\n";
/* DOMText */
$text = new DOMText('some text characters');
echo "Whole Text: " . $text->wholeText . "\n";
$text2 = $text->splitText(9);
echo "Split text: " . $text2->wholeText . "\n";
<?php

$dom = new DOMDocument('1.0', 'UTF-8');
$element = $dom->appendChild(new DOMElement('root'));
$comment = new DOMComment("This is the first comment.");
$comment->__construct("This is the second comment.");
$comment = $element->appendChild($comment);
print $dom->saveXML();