function insert_child_after(Frame $new_child, Frame $ref, $update_node = true) { if ($ref === $this->_last_child) { $this->append_child($new_child, $update_node); return; } if (is_null($ref)) { $this->prepend_child($new_child, $update_node); return; } if ($ref->_parent !== $this) { throw new DOMPDF_Exception("Reference child is not a child of this node."); } // Update the node if ($update_node) { if ($ref->_next_sibling) { $next_node = $ref->_next_sibling->_node; $this->_node->insertBefore($new_child->_node, $next_node); } else { $new_child->_node = $this->_node->appendChild($new_child); } } // Remove the child from its parent if ($new_child->_parent) { $new_child->_parent->remove_child($new_child, false); } $new_child->_parent = $this; $new_child->_prev_sibling = $ref; $new_child->_next_sibling = $ref->_next_sibling; if ($ref->_next_sibling) { $ref->_next_sibling->_prev_sibling = $new_child; } $ref->_next_sibling = $new_child; }
/** * Insert node as a first child or as the last child * (depending on position value) * * @param DOMNode $parent * @param DOMNode $node * @param bool $prepend */ public function insertNode(DOMNode $parent, DOMNode $node, $prepend = false) { if ($prepend === true) { $parent->insertBefore($node, $parent->firstChild); } else { $parent->appendChild($node); } }
/** * Insert nodes into target as first childs. * * @param DOMNode $targetNode * @param array|DOMNodeList|FluentDOM $contentNodes */ public static function insertChildrenBefore($targetNode, $contentNodes) { $result = array(); if ($targetNode instanceof DOMElement) { $firstChild = $targetNode->hasChildNodes() ? $targetNode->childNodes->item(0) : NULL; foreach ($contentNodes as $contentNode) { if ($contentNode instanceof DOMElement || $contentNode instanceof DOMText) { $result[] = $targetNode->insertBefore($contentNode->cloneNode(TRUE), $firstChild); } } } return $result; }
/** * Inserts a new child at the beginning of the Frame * * @param $child Frame The new Frame to insert * @param $update_node boolean Whether or not to update the DOM */ function prepend_child(FrameParser $child, $update_node = true) { if ($update_node) { $this->_node->insertBefore($child->_node, $this->_first_child ? $this->_first_child->_node : null); } // Remove the child from its parent if ($child->_parent) { $child->_parent->remove_child($child, false); } $child->_parent = $this; $child->_prev_sibling = null; // Handle the first child if (!$this->_first_child) { $this->_first_child = $child; $this->_last_child = $child; $child->_next_sibling = null; } else { $this->_first_child->_prev_sibling = $child; $child->_next_sibling = $this->_first_child; $this->_first_child = $child; } }
/** * 插入节点 * @param DOMNode $node XML节点 * @param DOMNode $newNode 新建XML节点 * @param DOMNode $oldNode XML节点 如果指定此参数新节点插入在此节点之前 * @return void */ public function insertNode(&$node, $newNode, $srcNode = NULL) { if ($srcNode == NULL) { $node->appendChild($newNode); } else { $node->insertBefore($newNode, $srcNode); } }
/** * Append a node to the given parent node if it exists. * @param DOMNode $node * @param DOMNode $parent * @param boolean $before If set then the node will be appended as the first child instead of the last. */ public function appendNode($node, $parent, $before = false) { if ($node && $node instanceof DOMNode && $parent && $parent instanceof DOMNode) { if ($before) { return $parent->insertBefore($node, $parent->firstChild); } else { return $parent->appendChild($node); } } else { $this->raiseError("Invalid node or parent to append to for appendNode."); } }
/** * Inserts the node sorted by entity and id to enable easier unit testing. * * @param DOMNode $xmlParent * @param DOMNode $xmlElement */ private function sortedInsertNode(DOMNode $xmlParent, DOMNode $xmlElement) { $xmlElementName = $xmlElement->nodeName; $xmlElementId = (int) $xmlElement->getAttribute('id'); $xmlNextSibling = NULL; $siblingIndex = 0; while ($siblingIndex < $xmlParent->childNodes->length && $xmlNextSibling == NULL) { $xmlSibling = $xmlParent->childNodes->item($siblingIndex); if ($xmlSibling->nodeType == XML_ELEMENT_NODE) { if ($xmlSibling->nodeName > $xmlElementName) { $xmlNextSibling = $xmlSibling; } else { if ($xmlSibling->nodeName == $xmlElementName) { $siblingId = $xmlSibling->getAttribute('id'); if ((int) $siblingId > $xmlElementId) { $xmlNextSibling = $xmlSibling; } } } } $siblingIndex++; } if ($xmlNextSibling != NULL) { $xmlParent->insertBefore($xmlElement, $xmlNextSibling); } else { $xmlParent->appendChild($xmlElement); } }
/** * Visit field list item * * @param DOMNode $root * @param ezcDocumentRstNode $node * @return void */ protected function visitFieldListItem(DOMNode $root, ezcDocumentRstNode $node) { // Get sectioninfo node, to add the stuff there. $secInfo = $root->getElementsByTagName('sectioninfo')->item(0); if ($secInfo === null) { // If not yet existant, create section info $secInfo = $root->ownerDocument->createElement('sectioninfo'); $root->insertBefore($secInfo, $root->firstChild); } $fieldListItemMapping = array('authors' => 'authors', 'description' => 'abstract', 'copyright' => 'copyright', 'version' => 'releaseinfo', 'date' => 'date', 'author' => 'author'); $fieldName = strtolower(trim($this->tokenListToString($node->name))); if (!isset($fieldListItemMapping[$fieldName])) { return $this->triggerError(E_NOTICE, "Unhandeled field list type '{$fieldName}'.", null, $node->token->line, $node->token->position); } $item = $this->document->createElement($fieldListItemMapping[$fieldName], htmlspecialchars($this->nodeToString($node))); $secInfo->appendChild($item); }
/** * Insert before * * @param \DOMNode $parentNode * @param \DOMNode $childNode * @return void */ protected function insertBefore(\DOMNode $parentNode, \DOMNode $childNode) { $importNode = $this->getDom()->importNode($childNode, true); $parentNode->insertBefore($importNode); }
/** * Gera as tags para o elemento: "enderDest" (Informações do Recebedor da Carga) * # = 185 * Nível = 2 * Os parâmetros para esta função são todos os elementos da tag "enderDest" do * tipo elemento (Ele = E|CE|A) e nível 3 * * @param string $xLgr Logradouro * @param string $nro Número * @param string $xCpl Complemento * @param string $xBairro Bairro * @param string $cMun Código do município (utilizar a tabela do IBGE) * @param string $xMun Nome do município * @param string $CEP CEP * @param string $UF Sigla da UF * @param string $cPais Código do país * @param string $xPais Nome do país * * @return \DOMElement */ public function enderDestTag($xLgr = '', $nro = '', $xCpl = '', $xBairro = '', $cMun = '', $xMun = '', $CEP = '', $UF = '', $cPais = '', $xPais = '') { $identificador = '#185 <enderDest> - '; $this->enderDest = $this->dom->createElement('enderDest'); $this->dom->addChild($this->enderDest, 'xLgr', $xLgr, true, $identificador . 'Logradouro'); $this->dom->addChild($this->enderDest, 'nro', $nro, true, $identificador . 'Número'); $this->dom->addChild($this->enderDest, 'xCpl', $xCpl, false, $identificador . 'Complemento'); $this->dom->addChild($this->enderDest, 'xBairro', $xBairro, true, $identificador . 'Bairro'); $this->dom->addChild($this->enderDest, 'cMun', $cMun, true, $identificador . 'Código do município (utilizar a tabela do IBGE)'); $this->dom->addChild($this->enderDest, 'xMun', $xMun, true, $identificador . 'Nome do município'); $this->dom->addChild($this->enderDest, 'CEP', $CEP, false, $identificador . 'CEP'); $this->dom->addChild($this->enderDest, 'UF', $UF, true, $identificador . 'Sigla da UF'); $this->dom->addChild($this->enderDest, 'cPais', $cPais, false, $identificador . 'Código do país'); $this->dom->addChild($this->enderDest, 'xPais', $xPais, false, $identificador . 'Nome do país'); $node = $this->dest->getElementsByTagName("email")->item(0); $this->dest->insertBefore($this->enderDest, $node); return $this->enderDest; }
/** * @param DOMDocument $doc The DomDocument * @param DOMNode $newnode The new node * @param DOMNode $node The node to prepend after * @return void */ private function prependChild(DOMDocument $doc, DOMNode $newnode, DOMNode $node) { if ($node->firstChild) { return $node->insertBefore($newnode, $node->firstChild); } else { return $node->appendChild($newnode); } }
/** * Search a WSDL XML DOM for "import" tags and import the files into * one large DOM for the entire WSDL structure * @ignore */ protected function mergeWSDLImports(DOMNode &$wsdlDOM, $continued = false, DOMDocument &$newRootDocument = NULL) { static $rootNode = NULL; static $rootDocument = NULL; /* If this is an external call, find the "root" defintions node */ if ($continued == false) { $rootNode = $wsdlDOM->getElementsByTagName('definitions')->item(0); $rootDocument = $wsdlDOM; } if ($newRootDocument == NULL) { $newRootDocument = $rootDocument; } //if (self::$debugMode) echo "Processing Node: ".$wsdlDOM->nodeName." which has ".$wsdlDOM->childNodes->length." child nodes".PHP_EOL; $nodesToRemove = array(); /* Loop through the Child nodes of the provided DOM */ foreach ($wsdlDOM->childNodes as $childNode) { //if (self::$debugMode) echo "\tProcessing Child Node: ".$childNode->nodeName." (".$childNode->localName.") which has ".$childNode->childNodes->length." child nodes".PHP_EOL; /* If this child is an IMPORT node, get the referenced WSDL, and remove the Import */ if ($childNode->localName == 'import') { /* Get the location of the imported WSDL */ if ($childNode->hasAttribute('location')) { $importURI = $childNode->getAttribute('location'); } else { if ($childNode->hasAttribute('schemaLocation')) { $importURI = $childNode->getAttribute('schemaLocation'); } else { $importURI = NULL; } } /* Only import if we found a URI - otherwise, don't change it! */ if ($importURI != NULL) { if (self::$debugMode) { echo "\tImporting data from: " . $importURI . PHP_EOL; } $importDOM = new DOMDocument(); @$importDOM->load($importURI); /* Find the "Definitions" on this imported node */ $importDefinitions = $importDOM->getElementsByTagName('definitions')->item(0); /* If we have "Definitions", import them one by one - Otherwise, just import at this level */ if ($importDefinitions != NULL) { /* Add all the attributes (namespace definitions) to the root definitions node */ foreach ($importDefinitions->attributes as $attribute) { /* Don't copy the "TargetNamespace" attribute */ if ($attribute->name != 'targetNamespace') { $rootNode->setAttributeNode($attribute); } } $this->mergeWSDLImports($importDefinitions, true, $importDOM); foreach ($importDefinitions->childNodes as $importNode) { //if (self::$debugMode) echo "\t\tInserting Child: ".$importNode->C14N(true).PHP_EOL; $importNode = $newRootDocument->importNode($importNode, true); $wsdlDOM->insertBefore($importNode, $childNode); } } else { //if (self::$debugMode) echo "\t\tInserting Child: ".$importNode->C14N(true).PHP_EOL; $importNode = $newRootDocument->importNode($importDOM->firstChild, true); $wsdlDOM->insertBefore($importNode, $childNode); } //if (self::$debugMode) echo "\t\tRemoving Child: ".$childNode->C14N(true).PHP_EOL; $nodesToRemove[] = $childNode; } } else { //if (self::$debugMode) echo 'Preserving node: '.$childNode->localName.PHP_EOL; if ($childNode->hasChildNodes()) { $this->mergeWSDLImports($childNode, true); } } } /* Actually remove the nodes (not done in the loop, as it messes up the ForEach pointer!) */ foreach ($nodesToRemove as $node) { $wsdlDOM->removeChild($node); } return $wsdlDOM; }
/** * @param string|Element|Tag|Field|\DOMNode $target css selector or Element * * @return Element|Tag|Field */ public function prependTo($target) { return $target->insertBefore($target->ownerDocument->importNode($this, true), $target->firstChild); }
/** Perform a "prepend" operation. @param $oAction The taconite action. @param $oElement The document element. */ protected function applyTagPrepend(DOMNode $oAction, DOMNode $oElement) { if ($oElement->firstChild) { $oReference = $oElement->firstChild; foreach ($oAction->childNodes as $oChild) { $oChild = $oElement->ownerDocument->importNode($oChild, true); $oElement->insertBefore($oChild, $oReference); } } else { foreach ($oAction->childNodes as $oChild) { $oChild = $oElement->ownerDocument->importNode($oChild, true); $oElement->appendChild($oChild); } } }
/** * This function inserts the signature element. * * The signature element will be appended to the element, unless $beforeNode is specified. If $beforeNode * is specified, the signature element will be inserted as the last element before $beforeNode. * * @param DOMNode $node The node the signature element should be inserted into. * @param DOMNode $beforeNode The node the signature element should be located before. * * @return DOMNode The signature element node */ public function insertSignature($node, $beforeNode = null) { $document = $node->ownerDocument; $signatureElement = $document->importNode($this->sigNode, true); if ($beforeNode == null) { return $node->insertBefore($signatureElement); } else { return $node->insertBefore($signatureElement, $beforeNode); } }
private function _prependTo($sCode, DOMNode $oRef) { $oTMPDocument = new DOMDocument(); $oTMPDocument->loadXML($sCode); $oInsertedNode = $this->importNode($oTMPDocument->firstChild, true); $oRef->insertBefore($oInsertedNode, $oRef->firstChild); }
/** * Prepend a node to the given existing node * * @param \DOMNode $newNode * @param \DOMNode $existingNode * @return \DOMNode the inserted node */ public function prependChild(\DOMNode $newNode, \DOMNode $existingNode) { return $existingNode->firstChild ? $existingNode->insertBefore($newNode, $existingNode->firstChild) : $existingNode->appendChild($newNode); }
/** * @param DOMDocument $dom * @param DOMXPath $xpath * @param DOMNode $parent * @param string $name * @param string $value * @return DOMElement */ private function &addNode($dom, $xpath, $parent, $name, $value = '') { $path = explode('/', rtrim($name, '/')); $name = end($path); $ref_node = null; $context = $parent->getNodePath(); switch ($context) { case '/theme': $before = array('name', 'description', 'files', 'about', 'settings', 'thumbs', 'locales'); break; case '/theme/settings/setting': $before = array('value', 'filename', 'name', 'description', 'options'); break; case '/theme/settings/setting/options/option': $before = array('name', 'description'); break; default: $before = array(); break; } if (!empty($before)) { do { } while ($before && $name != array_shift($before)); #find next element do { if ($query = array_shift($before)) { if (empty($xpath)) { $xpath = new DOMXPath($dom); } $query = $context . '/' . $query; if (($result = $xpath->query($query)) && $result->length) { $ref_node = $result->item(0); } } } while (!$ref_node && $before); } $element = $dom->createElement($name, $value); if ($ref_node) { $element = $parent->insertBefore($element, $ref_node); } else { $element = $parent->appendChild($element); } return $element; }
/** * Alters the dom to enclose the specified nodes with the micro-update * livepress mark tag. * * @access private * * @param array $nodes List of nodes to be enclosed. * @param DOMNode $parent_node Parent node where the nodes will be enclosed. * @param DOMDocument $dom The DOM where the nodes belongs. * @param array $current_ids All the current used ids on updates. * @param DOMNode $ref_node The nodes will be inserted before this one. */ private function enclose_nodes_by_chunk_mark_tag($nodes, $parent_node, $dom, $current_ids, $ref_node = null) { $chunk_mark = $dom->createElement(self::$chunks_tag); $chunk_id = $this->next_post_update_id($current_ids); $chunk_mark->setAttribute('id', $chunk_id); // Useful for one-line oEmbeds $chunk_mark->appendChild($dom->createTextNode("\n")); foreach ($nodes as $node) { $chunk_mark->appendChild($node); } // Useful for one-line oEmbeds $chunk_mark->appendChild($dom->createTextNode("\n")); $output = $dom->SaveXML($chunk_mark); $chunks_class = self::$chunks_class; if (preg_match('/\\[livepress_metainfo.+has_avatar.*\\]/s', $output)) { $chunks_class .= " " . self::$add_to_chunks_class_when_avatar; } $chunk_mark->setAttribute('class', $chunks_class); if ($ref_node) { $parent_node->insertBefore($chunk_mark, $ref_node); } else { $parent_node->appendChild($chunk_mark); } }
public function insert_node(DOMNode $node, DOMNode $new_node, $pos) { if ($pos === "after" || !$node->firstChild) { $node->appendChild($new_node); } else { $node->insertBefore($new_node, $node->firstChild); } $this->_build_tree_r($new_node); $frame_id = $new_node->getAttribute("frame_id"); $frame = $this->get_frame($frame_id); $parent_id = $node->getAttribute("frame_id"); $parent = $this->get_frame($parent_id); if ($pos === "before") { $parent->prepend_child($frame, false); } else { $parent->append_child($frame, false); } return $frame_id; }
/** * Returns the child node to be annotated. * * @param DOMNode $node * @param DOMXPath $xpath * @return DOMNode * @throws UnexpectedValueException */ protected function get_child_node($node, $xpath = null) { if (null !== $xpath) { // TODO(cs) Future... throw UnexpectedValueException($xpath); } else { $child = $node->firstChild; if (null === $child) { $node->appendChild(new DOMText()); $child = $node->firstChild; } else { if (1 === $child->nodeType) { if ($this->ignore_node($child->tagName)) { $node->insertBefore(new DOMText(), $child); $child = $node->firstChild; } } } } return $child; }
/** * appChildBefore * Acrescenta DOMElement a pai DOMElement * Caso o pai esteja vazio retorna uma exception com a mensagem * O parametro "child" pode ser vazio * @param \DOMNode $parent * @param \DOMNode $child * @param string $before * @param string $msg * @return void * @throws Exception\InvalidArgumentException */ public function appChildBefore(&$parent, $child, $before, $msg = '') { if (empty($parent)) { throw new Exception\InvalidArgumentException($msg); } $bnode = $parent->getElementsByTagName($before)->item(0); if (!empty($child) && !empty($bnode)) { $parent->insertBefore($child, $bnode); } }
/** * Insert the cost and effort breakdown. */ private function insertConsortiumFeedback(Feedback $feedback) { $elementInsertBefore = $this->elementConsortiumFeedback->nextSibling; $this->elementDocument->insertBefore($this->parseHeadingXML('ITEAHeading2wonum', 'STG evaluation'), $elementInsertBefore); $this->elementDocument->insertBefore($this->parseTableXML($this->parseProjectReviewEvaluation($feedback), true, false, false, false), $elementInsertBefore); $this->elementDocument->insertBefore($this->parseHeadingXML('ITEAHeading2wonum', 'Consortium feedback on the STG evaluation'), $elementInsertBefore); $this->elementDocument->insertBefore($this->parseParagraphXML($feedback->getReviewFeedback()), $elementInsertBefore); $this->elementDocument->insertBefore($this->parseHeadingXML('ITEAHeading2wonum', 'Public Authorities evaluation'), $elementInsertBefore); $this->elementDocument->insertBefore($this->parseTableXML($this->parseProjectEvaluation($feedback->getVersion()), true, false, false, false), $elementInsertBefore); $this->elementDocument->insertBefore($this->parseHeadingXML('ITEAHeading2wonum', 'Consortium feedback on the Public Authorities evaluation'), $elementInsertBefore); $this->elementDocument->insertBefore($this->parseParagraphXML($feedback->getEvaluationFeedback()), $elementInsertBefore); }