本文整理汇总了PHP中XML::appendChild方法的典型用法代码示例。如果您正苦于以下问题:PHP XML::appendChild方法的具体用法?PHP XML::appendChild怎么用?PHP XML::appendChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XML
的用法示例。
在下文中一共展示了XML::appendChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
<?php
// include xml lib
include_once '../lib.xml.inc.php';
// define list
$list = array(1 => 'this is a text-node', 'and here is another one', 'this is the 3rd element', 'and this is the final item!');
// create new xml object
$xml = new XML();
// create xml element
$root = $xml->createElement('xml');
$xml->appendChild($root);
// loop through list
foreach ($list as $i => $text) {
// set name of variable variable
$item = 'item' . $i;
// create 'item' element
${$item} = $xml->createElement('item');
// set an attribute, called 'id'
${$item}->setAttribute('id', $item);
// append a text-node to 'item'
${$item}->appendChild($xml->createTextNode($text));
// append the new item to the root element
$root->appendChild(${$item});
}
// show the dom
echo $xml->toString(1);
示例2: tag_open
/**
* При открытии тега, добавляем дите и устанавливаем указатель на него
*/
private function tag_open($parser, $tag, $attributes)
{
$this->pointer =& $this->pointer->appendChild($tag, $attributes);
}
示例3: appendDataXml
/**
* @param XML $xml
* @param array $data
* @return void
* @SuppressWarnings(PHPMD.ElseExpression)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function appendDataXml(XML &$xml, array &$data)
{
foreach ($data as $key => &$value) {
$child = new XML();
$child->setName($key);
$child->setCData(true);
$child->setRoot(false);
$type = gettype($value);
$child->setAttribute('type', $type);
switch ($type) {
case 'boolean':
$child->setValue((int) $value);
break;
case 'integer':
$child->setValue((int) $value);
break;
case 'double':
case 'float':
$child->setValue((double) $value);
break;
case 'string':
$child->setValue((string) $value);
break;
case 'array':
$this->appendDataXml($child, $value);
break;
case 'object':
$child->setAttribute('class', get_class($value));
if ($value instanceof self) {
$array = $value->getArray();
$this->appendDataXml($child, $array);
} else {
$serialize = serialize($value);
$child->setValue($serialize);
}
break;
case 'resource':
case 'null':
case 'unknown type':
default:
$child->setValue('null');
break;
}
$xml->appendChild($child);
}
}
示例4: array
<?php
// include xml lib
include_once '../lib.xml.inc.php';
// define a list
$list = array('first in line', 'second in line', 'third in line', 'fourth in line', 'fifth in line');
// create empty xml dom object
$xml = new XML();
// create a tree
$refChild = null;
$doc = $xml->createElement('document');
for ($i = 0; $i < count($list); $i++) {
// create new child
$child = 'node' . ($i + 1);
${$child} = $xml->createElement('text-node');
${$child}->setAttribute('id', $child);
${$child}->appendChild($xml->createTextNode($list[$i]));
// insert in tree & update refChild
$refChild = $doc->insertBefore(${$child}, $refChild);
}
// append the created 'doc' element to the root
$xml->appendChild($doc);
// dump dom using toString
echo $xml->toString(1);