DOMElement PHP Class Code Examples

This page contains top rated real world PHP examples of class DOMElement extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: xhtml.php Project: axelmdev/ecommerce
0
 /**
  * Recursively transform annotated XHtml elements to docbook
  *
  * @param DOMElement $xhtml
  * @param DOMElement $docbook
  * @param bool $significantWhitespace
  * @return void
  */
 protected function transformToDocbook(DOMElement $xhtml, DOMElement $docbook, $significantWhitespace = false)
 {
     if (($tagName = $xhtml->getProperty('type')) !== false) {
         $node = new DOMElement($tagName);
         $docbook->appendChild($node);
         $docbook = $node;
         if (($attributes = $xhtml->getProperty('attributes')) !== false) {
             foreach ($attributes as $name => $value) {
                 $node->setAttribute($name, htmlspecialchars($value));
             }
         }
     }
     foreach ($xhtml->childNodes as $child) {
         switch ($child->nodeType) {
             case XML_ELEMENT_NODE:
                 $this->transformToDocbook($child, $docbook, $significantWhitespace || $xhtml->getProperty('whitespace') === 'significant');
                 break;
             case XML_TEXT_NODE:
                 // Skip pure whitespace text nodes, except for
                 // intentionally converted <br> elements.
                 if (trim($text = $child->data) === '' && !$significantWhitespace && $xhtml->getProperty('whitespace') !== 'significant') {
                     continue;
                 }
                 if ($xhtml->getProperty('whitespace') === 'significant' || $significantWhitespace) {
                     // Don't normalize inside nodes with significant whitespaces.
                     $text = new DOMText($text);
                     $docbook->appendChild($text);
                 } else {
                     if ($this->isInlineElement($docbook)) {
                         $text = new DOMText(preg_replace('(\\s+)', ' ', $text));
                         $docbook->appendChild($text);
                     } else {
                         // Wrap contents into a paragraph, if we are yet
                         // outside of an inline element.
                         $text = new DOMText(trim(preg_replace('(\\s+)', ' ', $text)));
                         $para = $docbook->ownerDocument->createElement('para');
                         $para->appendChild($text);
                         $docbook->appendChild($para);
                     }
                 }
                 break;
             case XML_CDATA_SECTION_NODE:
                 //                    $data = new DOMCharacterData();
                 //                    $data->appendData( $child->data );
                 //                    $docbook->appendChild( $data );
                 break;
             case XML_ENTITY_NODE:
                 // Seems not required, as entities in the source document
                 // are automatically transformed back to their text
                 // targets.
                 break;
             case XML_COMMENT_NODE:
                 // Ignore comments
                 break;
                 $comment = new DOMElement('comment', $child->data);
                 $docbook->appendChild($comment);
                 break;
         }
     }
 }
Example #2
Show file File: dom-element-lifetime.php Project: badlamer/hhvm
0
function two()
{
    $root = new DOMElement('root');
    $child = new DOMElement('child');
    $root->appendChild($child);
    var_dump($root->C14N());
}
Example #3
Show file File: CheckstylePrinter.php Project: ablyler/phan
0
 /** flush printer buffer */
 public function flush()
 {
     $document = new \DomDocument('1.0', 'ISO-8859-15');
     $checkstyle = new \DOMElement('checkstyle');
     $document->appendChild($checkstyle);
     $checkstyle->appendChild(new \DOMAttr('version', '6.5'));
     // Write each file to the DOM
     foreach ($this->files as $file_name => $error_list) {
         $file = new \DOMElement('file');
         $checkstyle->appendChild($file);
         $file->appendChild(new \DOMAttr('name', $file_name));
         // Write each error to the file
         foreach ($error_list as $error_map) {
             $error = new \DOMElement('error');
             $file->appendChild($error);
             // Write each element of the error as an attribute
             // of the error
             foreach ($error_map as $key => $value) {
                 $error->appendChild(new \DOMAttr($key, (string) $value));
             }
         }
     }
     $this->output->write($document->saveXML());
     $this->files = [];
 }
Example #4
Show file File: IndexResponseFormatter.php Project: advance100/yunjianyi
0
 /**
  * @param DOMElement $element
  * @param mixed $data
  */
 protected function buildXml($element, $data)
 {
     if (is_object($data)) {
         $child = new DOMElement($this->itemTag);
         $element->appendChild($child);
         if ($data instanceof Arrayable) {
             $this->buildXml($child, $data->toArray());
         } else {
             $array = [];
             foreach ($data as $name => $value) {
                 $array[$name] = $value;
             }
             $this->buildXml($child, $array);
         }
     } elseif (is_array($data)) {
         foreach ($data as $name => $value) {
             if (is_int($name) && is_object($value)) {
                 $this->buildXml($element, $value);
             } elseif (is_array($value) || is_object($value)) {
                 $child = new DOMElement(is_int($name) ? $this->itemTag : $name);
                 $element->appendChild($child);
                 $this->buildXml($child, $value);
             } else {
                 $child = new DOMElement(is_int($name) ? $this->itemTag : $name);
                 $element->appendChild($child);
                 $child->appendChild(new DOMText((string) $value));
             }
         }
     } else {
         $element->appendChild(new DOMText((string) $data));
     }
 }
Example #5
Show file File: pcss.php Project: axelmdev/ecommerce
0
 /**
  * Pre-process styles using $stylePreProcessors.
  * 
  * @param DOMElement $docBookElement 
  * @param DOMElement $odtElement 
  * @param array $styles 
  * @return array
  */
 private function preProcessStyles(DOMElement $docBookElement, DOMElement $odtElement, array $styles)
 {
     foreach ($this->stylePreProcessors as $preProcessor) {
         $styles = $preProcessor->process($this->styleInfo, $docBookElement, $odtElement, $styles);
     }
     return $styles;
 }
Example #6
Show file File: Assert.php Project: CHRISTOPHERVANDOMME/zf2complet
0
 /**
  * Asserts that a hierarchy of DOMElements matches.
  *
  * @param DOMElement $expectedElement
  * @param DOMElement $actualElement
  * @param bool       $checkAttributes
  * @param string     $message
  *
  * @since  Method available since Release 3.3.0
  */
 public static function assertEqualXMLStructure(DOMElement $expectedElement, DOMElement $actualElement, $checkAttributes = false, $message = '')
 {
     $tmp = new DOMDocument();
     $expectedElement = $tmp->importNode($expectedElement, true);
     $tmp = new DOMDocument();
     $actualElement = $tmp->importNode($actualElement, true);
     unset($tmp);
     self::assertEquals($expectedElement->tagName, $actualElement->tagName, $message);
     if ($checkAttributes) {
         self::assertEquals($expectedElement->attributes->length, $actualElement->attributes->length, sprintf('%s%sNumber of attributes on node "%s" does not match', $message, !empty($message) ? "\n" : '', $expectedElement->tagName));
         for ($i = 0; $i < $expectedElement->attributes->length; $i++) {
             $expectedAttribute = $expectedElement->attributes->item($i);
             $actualAttribute = $actualElement->attributes->getNamedItem($expectedAttribute->name);
             if (!$actualAttribute) {
                 self::fail(sprintf('%s%sCould not find attribute "%s" on node "%s"', $message, !empty($message) ? "\n" : '', $expectedAttribute->name, $expectedElement->tagName));
             }
         }
     }
     PHPUnit_Util_XML::removeCharacterDataNodes($expectedElement);
     PHPUnit_Util_XML::removeCharacterDataNodes($actualElement);
     self::assertEquals($expectedElement->childNodes->length, $actualElement->childNodes->length, sprintf('%s%sNumber of child nodes of "%s" differs', $message, !empty($message) ? "\n" : '', $expectedElement->tagName));
     for ($i = 0; $i < $expectedElement->childNodes->length; $i++) {
         self::assertEqualXMLStructure($expectedElement->childNodes->item($i), $actualElement->childNodes->item($i), $checkAttributes, $message);
     }
 }
Example #7
Show file File: XmlResponseFormatter.php Project: Jaaviieer/PrograWeb
0
 /**
  * @param DOMElement $element
  * @param mixed $data
  */
 protected function buildXml($element, $data)
 {
     if (is_object($data)) {
         $child = new DOMElement(StringHelper::basename(get_class($data)));
         $element->appendChild($child);
         if ($data instanceof Arrayable) {
             $this->buildXml($child, $data->toArray());
         } else {
             $array = [];
             foreach ($data as $name => $value) {
                 $array[$name] = $value;
             }
             $this->buildXml($child, $array);
         }
     } elseif (is_array($data)) {
         foreach ($data as $name => $value) {
             if (is_int($name) && is_object($value)) {
                 $this->buildXml($element, $value);
             } elseif (is_array($value) || is_object($value)) {
                 $child = new DOMElement(is_int($name) ? $this->itemTag : $name);
                 $element->appendChild($child);
                 $this->buildXml($child, $value);
             } else {
                 $child = new DOMElement(is_int($name) ? $this->itemTag : $name);
                 $element->appendChild($child);
                 $child->appendChild(new DOMText((string) $value));
             }
         }
     } else {
         $element->appendChild(new DOMText((string) $data));
     }
 }
Example #8
Show file File: DOMDocument.php Project: oliver-graetz/xmlbuilder
0
 /**
  * importElement
  *
  * @param DOMElement $import
  * @param DOMElement $element
  * @access public
  * @return mixed
  */
 public function appendDomElement(\DOMElement $import, \DOMElement $element = null, $deep = true)
 {
     $import = $this->importNode($import, $deep);
     if (is_null($element)) {
         return $this->firstChild->appendChild($import);
     }
     return $element->appendChild($import);
 }
Example #9
Show file File: SignedElementHelper.php Project: SysBind/saml2
0
 /**
  * Sign the given XML element.
  *
  * @param \DOMElement      $root         The element we should sign.
  * @param \DOMElement|null $insertBefore The element we should insert the signature node before.
  * @return \DOMElement|null
  */
 protected function signElement(\DOMElement $root, \DOMElement $insertBefore = null)
 {
     if ($this->signatureKey === null) {
         /* We cannot sign this element. */
         return null;
     }
     Utils::insertSignature($this->signatureKey, $this->certificates, $root, $insertBefore);
     return $root;
 }
Example #10
Show file File: anchor.php Project: jordanmanning/ezpublish
0
 /**
  * Creates a ref-mark as the first element of the given $odtElement, based 
  * on the ID attribute of the given $docbookElement.
  * 
  * @param DOMElement $docbookElement 
  * @param DOMElement $odtElement 
  */
 protected function createRefMark(DOMElement $docbookElement, DOMElement $odtElement)
 {
     // Work around for DocBook inconsistency in using ID or id. id
     // would  be correct, if one follows the specs here…
     if ($docbookElement->hasAttribute('ID') || $docbookElement->hasAttribute('id')) {
         $refMark = $odtElement->insertBefore($odtElement->ownerDocument->createElementNS(ezcDocumentOdt::NS_ODT_TEXT, 'text:reference-mark'), $odtElement->firstChild);
         $refMark->setAttributeNS(ezcDocumentOdt::NS_ODT_TEXT, 'text:name', $docbookElement->hasAttribute('ID') ? $docbookElement->getAttribute('ID') : $docbookElement->getAttribute('id'));
     }
 }
Example #11
Show file File: SignedElementHelper.php Project: danielkjfrog/docker
0
 /**
  * Sign the given XML element.
  *
  * @param DOMElement      $root         The element we should sign.
  * @param DOMElement|NULL $insertBefore The element we should insert the signature node before.
  * @return DOMElement|NULL
  */
 protected function signElement(DOMElement $root, DOMElement $insertBefore = NULL)
 {
     if ($this->signatureKey === NULL) {
         /* We cannot sign this element. */
         return NULL;
     }
     SAML2_Utils::insertSignature($this->signatureKey, $this->certificates, $root, $insertBefore);
     return $root;
 }
Example #12
Show file File: ContentExtractor.php Project: inscriptionweb/inMyPluxml
0
 private function isDescendant(DOMElement $parent, DOMElement $child)
 {
     $node = $child->parentNode;
     while ($node != null) {
         if ($node->isSameNode($parent)) {
             return true;
         }
         $node = $node->parentNode;
     }
     return false;
 }