本文整理汇总了PHP中DOMNode::insertBefore方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMNode::insertBefore方法的具体用法?PHP DOMNode::insertBefore怎么用?PHP DOMNode::insertBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMNode
的用法示例。
在下文中一共展示了DOMNode::insertBefore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
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;
}
示例2: insertNode
/**
* 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);
}
}
示例3: insertChildrenBefore
/**
* 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;
}
示例4:
/**
* 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;
}
}
示例5: insertNode
/**
* 插入节点
* @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);
}
}
示例6: appendNode
/**
* 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.");
}
}
示例7: sortedInsertNode
/**
* 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);
}
}
示例8: visitFieldListItem
/**
* 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);
}
示例9: insertBefore
/**
* 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);
}
示例10: enderDestTag
/**
* 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;
}
示例11: prependChild
/**
* @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);
}
}
示例12: mergeWSDLImports
/**
* 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;
}
示例13: prependTo
/**
* @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);
}
示例14: applyTagPrepend
/**
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);
}
}
}
示例15: insertSignature
/**
* 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);
}
}