本文整理汇总了PHP中DOMDocument::appendChild方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMDocument::appendChild方法的具体用法?PHP DOMDocument::appendChild怎么用?PHP DOMDocument::appendChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::appendChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* The Construct
*
* @param string $filename
* @param arrray $arguments
*
* @return SiteQ_Report_AbstractReport
*/
public function __construct($filename, $arguments)
{
parent::__construct($filename, $arguments);
$this->_document = new DOMDocument();
$this->_root = $this->_document->createElement('siteq');
$this->_document->appendChild($this->_root);
}
示例2: __construct
/**
* Constructor
*
* @return void
* @access public
* @since 1/17/08
*/
public function __construct()
{
$this->doc = new Harmoni_DOMDocument('1.0', 'UTF-8');
$this->doc->appendChild($this->doc->createElement('rss'));
$this->doc->documentElement->setAttribute('version', "2.0");
$this->doc->documentElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:excerpt', 'http://wordpress.org/export/1.1/excerpt/');
$this->doc->documentElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:content', 'http://purl.org/rss/1.0/modules/content/');
$this->doc->documentElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:wfw', 'http://wellformedweb.org/CommentAPI/');
$this->doc->documentElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$this->doc->documentElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:wp', 'http://wordpress.org/export/1.1/');
$this->channel = $this->doc->documentElement->appendChild($this->doc->createElement('channel'));
// create some comment placeholders for organizing our elements
$this->channel->appendChild($this->doc->createComment("Begin - Meta"));
$this->endMeta = $this->channel->appendChild($this->doc->createComment("End - Meta"));
$this->channel->appendChild($this->doc->createComment("Begin - Authors"));
$this->endAuthors = $this->channel->appendChild($this->doc->createComment("End - Authors"));
$this->channel->appendChild($this->doc->createComment("Begin - Categories"));
$this->endCategories = $this->channel->appendChild($this->doc->createComment("End - Categories"));
$this->channel->appendChild($this->doc->createComment("Begin - Tags"));
$this->endTags = $this->channel->appendChild($this->doc->createComment("End - Tags"));
$this->channel->appendChild($this->doc->createComment("Begin - Files"));
$this->endFiles = $this->channel->appendChild($this->doc->createComment("End - Files"));
$this->channel->insertBefore($this->getElement('generator', 'http://segue.middlebury.edu/'), $this->endMeta);
$this->xpath = new DOMXPath($this->doc);
$this->xpath->registerNamespace('wp', 'http://wordpress.org/export/1.1/');
}
示例3: prepare
/**
* {@inheritdoc}
*/
public function prepare()
{
$this->xml = new \DOMDocument();
$this->rootNode = $this->xml->createElement($this->rootNodeName);
$this->xml->appendChild($this->rootNode);
return $this;
}
示例4: build
public function build()
{
$this->doc = new \DOMDocument('1.0', 'UTF-8');
if ($this->structure) {
$this->doc->appendChild($this->doc->importNode(dom_import_simplexml($this->structure), true));
}
}
示例5: generateXML
/**
* @param DOMDocument $documentXml
* @param DOMDocument $parent
*/
public function generateXML($documentXml, $parent)
{
if ($this->getType() == EiDataSetStructure::$TYPE_NODE) {
$element = $documentXml->createElement($this->getEiDataSetStructure()->getXMLTag());
/** @var Doctrine_Node_NestedSet $node */
$node = $this->getNode();
/** @var EiTestSetDataSet[] $descendants */
$descendants = $node->getDescendants(1);
if ($descendants !== false) {
/** @var EiTestSetDataSet $leaf */
foreach ($descendants as $leaf) {
if ($leaf->getType() == EiDataSetStructure::$TYPE_LEAF) {
$leaf->generateXML($documentXml, $element);
}
}
}
$parent->appendChild($element);
if ($descendants !== false) {
// On parcours les fils.
/** @var EiNodeDataSet $child */
foreach ($node->getDescendants(1) as $child) {
if ($child->getType() == EiDataSetStructure::$TYPE_NODE) {
// On génère l'élément XSD relatif au noeud fils.
$child->generateXML($documentXml, $element);
}
}
}
} else {
$element = $documentXml->createElement($this->getEiDataSetStructure()->getXMLTag(), htmlspecialchars($this->getValue()));
$parent->appendChild($element);
}
}
示例6:
/**
* Creates a new xml sitemag generator
*/
function __construct()
{
$this->domDoc = new \DOMDocument("1.0", "utf-8");
$this->domDoc->formatOutput = true;
$this->CreateUrlset();
$this->domDoc->appendChild($this->urlset);
}
示例7: run
/**
*
*/
public function run()
{
$nRecords = mysqli_query($this->conn, 'SELECT COUNT(*) AS `qty` FROM `data`;')->fetch_object()->qty;
$xml = new DOMDocument("1.0");
$xml->formatOutput = true;
$xml->encoding = 'UTF-8';
$root = $xml->appendChild(new DOMElement('records'));
$pBar = new ProgressBar($nRecords);
$totalCost = 0;
$offset = 0;
while ($offset < $nRecords) {
$record = mysqli_query($this->conn, 'SELECT * FROM `data` LIMIT 1 OFFSET ' . $offset)->fetch_assoc();
$pid = $record['product_id'];
$xmlRecord = $root->appendChild(new DOMElement('record'));
$xmlRecord->setAttribute('id', $record['id']);
$xmlRecord->appendChild(new DOMElement('product_id', $pid));
$xmlRecord->appendChild(new DOMElement('cost', $record['cost']));
$product = $this->getRecord($pid);
$productRatio = isset($product['product_ratio']) ? $product['product_ratio'] : 0;
$familyRatio = isset($product['family_ratio']) ? $product['family_ratio'] : 0;
$realCost = $record['cost'] * $productRatio * $familyRatio;
$xmlRecord->appendChild(new DOMElement('relative_cost', $realCost));
$xmlRecord->appendChild(new DOMElement('product_name', $product['product_name']));
$xmlRecord->appendChild(new DOMElement('family_id', $product['family_id']));
$xmlRecord->appendChild(new DOMElement('family_name', $product['family_name']));
$totalCost += $realCost;
$offset++;
$pBar->updateValue($offset);
}
print "\n";
$xml->appendChild(new DOMElement('total_cost', $totalCost));
print $xml->saveXML();
print sprintf("this script lasted %d seconds !\n", intval(date("U") - $this->startTime));
}
示例8: saveXML
/**
* Recuperer la configuration au format XML.
*/
public function saveXML()
{
$existing = array();
$attributes = $this->domdocument->getElementsByTagName('attribute');
foreach ($attributes as $attribute) {
$existing[$attribute->getAttribute('name')] = $attribute;
}
if ($this->domdocument->getElementsByTagName('config')->item(0) == null) {
$root = $this->domdocument->createElement('config');
$this->domdocument->appendChild($root);
} else {
$root = $this->domdocument->getElementsByTagName('config')->item(0);
}
foreach ($this->config as $attribute => $value) {
if (array_key_exists($attribute, $existing)) {
$node = $existing[$attribute];
} else {
$node = $this->domdocument->createElement('attribute');
$root->appendChild($node);
$node->setAttribute('name', $attribute);
}
$node->setAttribute('value', $value);
}
$configNodes = $root->getElementsByTagName('attribute');
foreach ($configNodes as $node) {
if (!array_key_exists($node->getAttribute('name'), $this->config)) {
$root->removeChild($node);
}
}
$out = $this->domdocument->saveXML();
return $out;
}
示例9: render
public function render()
{
$dom = $dom = new \DOMDocument('1.0');
$header = $dom->createElement('h1', $this->_name);
$dom->appendChild($header);
$form = $dom->createElement('form');
$form->setAttribute('action', $this->_action);
$form->setAttribute('method', $this->_method);
$form->setAttribute('id', $this->_id);
if ($this->_enctype != null) {
$form->setAttribute('enctype', $this->_enctype);
}
$dom->appendChild($form);
foreach ($this->_fields as $name => $field) {
if (($field->type == self::FIELD_INPUT_HIDDEN || $field->type == self::FIELD_NOT_RENDER) && $field->error != null) {
$err = $dom->createElement('div', $field->error);
$err->setAttribute('class', 'form-field-error');
$dom->insertBefore($err, $form);
}
if (($rendered = $this->createField($name)->render($dom)) != null) {
$form->appendChild($rendered);
}
}
return $dom->saveHTML();
}
示例10: addSortableScriptOnGrid
/**
* Appends the "sortable" js code to the bottom of ajax-Request for the category-products loaded after
* changing sort order.
*
* @param Varien_Event_Observer $observer
*/
public function addSortableScriptOnGrid(Varien_Event_Observer $observer)
{
$_block = $observer->getBlock();
$_type = $_block->getType();
if (Mage::helper('ffuenf_categoryproductsortbackend')->isExtensionActive() && $_type == 'adminhtml/catalog_category_tab_product') {
$content = $observer->getTransport()->getHtml();
$dom = new DOMDocument('1.0', 'utf-8');
$doc = new DOMDocument('1.0', 'utf-8');
$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'));
foreach ($dom->getElementsByTagName('select') as $element) {
if ($element->getAttribute('name') == 'limit') {
$option = $dom->createElement('option');
$option->appendChild($dom->createTextNode('All'));
$option->setAttribute('value', 0);
$option = $element->appendChild($option);
}
}
$additionalHtml = $this->appendScript($content);
$additionalDoc = new DOMDocument();
$additionalDoc->loadHTML($additionalHtml);
$additionalDocScript = $additionalDoc->getElementsByTagName('script')->item(0);
$body = $dom->getElementsByTagName('body')->item(0);
foreach ($body->childNodes as $child) {
$doc->appendChild($doc->importNode($child, true));
}
$doc->appendChild($doc->importNode($additionalDocScript, true));
$content = $doc->saveHTML();
$observer->getTransport()->setHtml($content);
}
}
示例11: createUrlSet
private function createUrlSet()
{
$this->dom = new \DOMDocument('1.0', 'UTF-8');
$this->urlset = $this->dom->createElement("urlset");
$this->urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
$this->dom->appendChild($this->urlset);
}
示例12: serialize
/**
* @param ModelInterface $model
*
* @return \DOMDocument
*/
public function serialize(ModelInterface $model)
{
$this->dom = new \DOMDocument('1.0');
$this->dom->formatOutput = true;
$element = $this->visitModel($model);
$this->dom->appendChild($element);
return $this->dom;
}
示例13: initialize
/**
* Initializes this exporter.
*
* @return void
*/
public function initialize()
{
$this->xml = new \DOMDocument('1.0', 'utf-8');
$this->xml->formatOutput = true;
$document_element = new \DOMElement('project');
$this->xml->appendChild($document_element);
$document_element->setAttribute('version', \phpDocumentor\Application::VERSION);
$document_element->setAttribute('title', $this->parser->getTitle());
}
示例14: __construct
/**
* Constructor.
*
* @param mixed $out
* @param bool $reportUselessTests
*/
public function __construct($out = null, $reportUselessTests = false)
{
$this->document = new DOMDocument('1.0', 'UTF-8');
$this->document->formatOutput = true;
$this->root = $this->document->createElement('testsuites');
$this->document->appendChild($this->root);
parent::__construct($out);
$this->reportUselessTests = $reportUselessTests;
}
示例15: dumpSchema
/**
* Dumps a single Schema model into an XML formatted version.
*
* @param Schema $schema The schema object
* @param boolean $doFinalInitialization Whether or not to validate the schema
* @return string
*/
public function dumpSchema(Schema $schema, $doFinalInitialization = true)
{
$rootNode = $this->document->createElement('app-data');
$this->document->appendChild($rootNode);
foreach ($schema->getDatabases($doFinalInitialization) as $database) {
$this->appendDatabaseNode($database, $rootNode);
}
return trim($this->document->saveXML());
}