本文整理汇总了PHP中DOMNode::appendChild方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMNode::appendChild方法的具体用法?PHP DOMNode::appendChild怎么用?PHP DOMNode::appendChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMNode
的用法示例。
在下文中一共展示了DOMNode::appendChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array2domAttr
/**
* Add dom attributes from array
* @static
* @param \DOMElement|\DOMNode $node
* @param array $array
* @param bool $verbal
*/
public static function array2domAttr(&$node, $array, $verbal = false)
{
if (is_array($array) and !empty($array)) {
foreach ($array as $k => $v) {
if (is_numeric($k) and !is_array($v) and !is_object($v) and ctype_alnum($v)) {
$node->appendChild($node->ownerDocument->createElement(ctype_alpha($v[0]) ? $v : "_{$v}"));
} elseif (is_array($v)) {
if (is_numeric($k)) {
$k = "_{$k}";
}
$newNode = $node->appendChild($node->ownerDocument->createElement($k));
self::array2domAttr($newNode, $v, $verbal);
} elseif (is_object($v)) {
} else {
if ($verbal) {
if (is_null($v)) {
$v = 'null';
} elseif ($v === false) {
$v = 'false';
} elseif ($v === true) {
$v = 'true';
} elseif ($v === 0) {
$v = '0';
}
}
$node->setAttribute(ctype_alpha($k[0]) ? $k : "_{$k}", $v);
}
}
}
}
示例2: copyNodes
protected function copyNodes(DOMNode $dirty, DOMNode $clean)
{
foreach ($dirty->attributes as $name => $valueNode) {
/* Copy over allowed attributes */
if (isset($this->allowed[$dirty->nodeName][$name])) {
$attr = $clean->ownerDocument->createAttribute($name);
$attr->value = $valueNode->value;
$clean->appendChild($attr);
}
}
foreach ($dirty->childNodes as $child) {
/* Copy allowed elements */
if ($child->nodeType == XML_ELEMENT_NODE && isset($this->allowed[$child->nodeName])) {
$node = $clean->ownerDocument->createElement($child->nodeName);
$clean->appendChild($node);
/* Examine children of this allowed element */
$this->copyNodes($child, $node);
} else {
if ($child->nodeType == XML_TEXT_NODE) {
$text = $clean->ownerDocument->createTextNode($child->textContent);
$clean->appendChild($text);
}
}
}
}
示例3: createNode
function createNode(DOMDocument $targetdoc, DOMNode $targetnode, DOMNode $entry, $with_content = true)
{
$a = $targetdoc->createElement('a');
$targetnode->appendChild($a);
$a->setAttribute('href', $entry->getElementsByTagName('id')->item(0)->nodeValue);
$a->appendChild($targetdoc->createElement('b', date('Y-m-d H:i:s', strtotime($entry->getElementsByTagName('updated')->item(0)->nodeValue)) . ': '));
$a->appendChild($targetdoc->createTextNode($entry->getElementsByTagName('title')->item(0)->nodeValue));
if ($with_content && ($contents = $entry->getElementsByTagName('content')) && $contents->length) {
$div = $targetdoc->createElement('div');
$targetnode->appendChild($div);
$div->appendChild($targetdoc->importNode($contents->item(0), true));
}
}
示例4: append_nodes_to
/**
*
* @param DOMNode $dest_node
* @param DOMNodeList $imported_nodes
*/
protected function append_nodes_to(DOMNode $dest_node, DOMNodeList $imported_nodes)
{
$dom = $this->dom;
foreach ($imported_nodes as $node) {
if ($node instanceof DOMAttr) {
$dest_node->appendChild($dom->createTextNode($node->nodeValue . "\n"));
} else {
$dest_node->appendChild($dom->importNode($node, true));
$dest_node->appendChild($dom->createTextNode("\n"));
// добавить WHITESPACE
}
}
}
示例5: appendChildren
/**
* Append to content nodes to the target nodes.
*
* @param array|\Traversable $contentNodes
* @return array new nodes
*/
public function appendChildren($contentNodes)
{
$result = array();
if ($this->_node instanceof \DOMElement) {
foreach ($contentNodes as $contentNode) {
/** @var \DOMNode $contentNode */
if (Constraints::isNode($contentNode)) {
$result[] = $this->_node->appendChild($contentNode->cloneNode(TRUE));
}
}
}
return $result;
}
示例6: appendToDom
public function appendToDom(\DOMNode $parent)
{
$node = $parent->appendChild(new \DOMElement('PaymentAccount'));
$node->appendChild(new \DOMElement('PaymentAccountID', $this['PaymentAccountID']));
$node->appendChild(new \DOMElement('PaymentAccountType', $this['PaymentAccountType']));
$node->appendChild(new \DOMElement('PaymentAccountReferenceNumber', $this['PaymentAccountReferenceNumber']));
}
示例7: castElement
/**
* Caste l'élement spécifié
*
* @param DOMNode $nodeParent DOMNode
* @param String $value String
*
* @return void
*/
function castElement($nodeParent, $value)
{
$value = utf8_encode($value);
$attribute = $this->createAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:type");
$attribute->nodeValue = $value;
$nodeParent->appendChild($attribute);
}
示例8: getXml
/**
* @param \DOMNode $parent
* @param SerializationContext $context
* @return \DOMElement
*/
public function getXml(\DOMNode $parent, SerializationContext $context)
{
$result = $context->getDocument()->createElementNS(Protocol::NS_METADATA, 'md:NameIDFormat');
$parent->appendChild($result);
$result->nodeValue = $this->value;
return $result;
}
示例9:
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;
}
示例10: _buildNode
/**
* Builds and creates the Atom XML nodes required by this date
*
* The element node representing this date is created separately and
* passed as the first parameter of this method.
*
* @param DOMNode $node the node representing this date.
*
* @return void
*/
protected function _buildNode(DOMNode $node)
{
$document = $node->ownerDocument;
$date_string = $this->_date->format('c');
$text_node = $document->createTextNode($date_string);
$node->appendChild($text_node);
}
示例11: _buildNode
/**
* Builds and creates the Atom XML nodes required by this content
*
* The element node representing this content is created separately and
* passed as the first parameter of this method.
*
* The text content of this content is created as a CDATA section.
*
* @param DOMNode $node the node representing this content. Extra nodes
* should be created and added to this node.
*
* @return void
*/
protected function _buildNode(DOMNode $node)
{
$document = $node->ownerDocument;
$node->setAttributeNS(XML_Atom_Node::NS, 'type', $this->_type);
$cdata_node = $document->createCDATASection($this->_text);
$node->appendChild($cdata_node);
}
示例12: postProcessXML
/**
* @param \DOMNode $node
*/
protected function postProcessXML($node)
{
// дата релиза
if (!is_null($this->release)) {
$release = date('d-m-Y', strtotime($this->release . ' 00:00:00'));
$node->setAttribute('release', $release);
$xDate = explode('-', $release);
$fullDate = $xDate[0] . ' ' . \Difra\Locales::getInstance()->getXPath('portfolio/months/m_' . $xDate[1]) . ' ' . $xDate[2];
$node->setAttribute('fullDate', $fullDate);
}
// авторы
if (!is_null($this->authors)) {
$authorsArray = unserialize($this->authors);
if (!empty($authorsArray)) {
foreach ($authorsArray as $k => $data) {
if (isset($data['role'])) {
$roleNode = $node->appendChild($node->ownerDocument->createElement('role'));
$roleNode->setAttribute('name', $data['role']);
if (isset($data['contibutors']) && is_array($data['contibutors'])) {
foreach ($data['contibutors'] as $cName) {
$cNode = $roleNode->appendChild($node->ownerDocument->createElement('contibutor'));
$cNode->setAttribute('name', $cName);
}
}
}
}
}
}
}
示例13: appendToDom
public function appendToDom(\DOMNode $parent)
{
$node = $parent->appendChild(new \DOMElement('Card'));
// Append parameters.
$node->appendChild(new \DOMElement('CVV', $this['CVV']));
// Only one of the following field groups needs to be included; If more
// than one is present, they will be given the following order of
// precedence. To avoid unintended results only populate one field per
// transaction.
$cardData = ['MagneprintData' => false, 'EncryptedTrack2Data' => true, 'EncryptedTrack1Data' => true, 'EncryptedCardData' => true, 'Track2Data' => false, 'Track1Data' => false];
do {
foreach ($cardData as $field => $isEncrypted) {
if (!empty($this[$field])) {
$node->appendChild(new \DOMElement($field, strtoupper($this[$field])));
if ($isEncrypted) {
$node->appendChild(new \DOMElement('CardDataKeySerialNumber', strtoupper($this['CardDataKeySerialNumber'])));
$node->appendChild(new \DOMElement('EncryptedFormat', $this['EncryptedFormat']));
}
break 2;
}
}
if (!empty($this['CardNumber'])) {
$node->appendChild(new \DOMElement('CardNumber', $this['CardNumber']));
}
if (!empty($this['ExpirationMonth']) && !empty($this['ExpirationYear'])) {
$time = gmmktime(0, 0, 0, $this['ExpirationMonth'], 1, $this['ExpirationYear']);
$node->appendChild(new \DOMElement('ExpirationMonth', gmdate('m', $time)));
$node->appendChild(new \DOMElement('ExpirationYear', gmdate('y', $time)));
}
} while (false);
}
示例14: appendChild
/**
* @param \DOMNode $node
* @return \DOMNode|null
*/
public function appendChild(\DOMNode $node)
{
if ($node->ownerDocument === $this->ownerDocument) {
return parent::appendChild($node);
}
return DOMStatic::appendTo($node, $this);
}
示例15: getTracksChannelsXML
/**
* Возвращает список каналов по трекам в XML
* @param array $tracks
* @param \DOMNode $node
* @return void
*/
public function getTracksChannelsXML($tracks, $node)
{
$db = \Difra\MySQL::getInstance();
$tracks = array_map('intval', $tracks);
$channelsXML = $node->appendChild($node->ownerDocument->createElement('tracksInChannels'));
$db->fetchXML($channelsXML, "SELECT `id`, `channel` FROM `radio_tracks` WHERE `id` IN (" . implode(', ', $tracks) . ")");
}