本文整理汇总了PHP中DOMDocument::CreateElement方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMDocument::CreateElement方法的具体用法?PHP DOMDocument::CreateElement怎么用?PHP DOMDocument::CreateElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::CreateElement方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addNode
private function addNode($id, $name, $conetnt)
{
$article_db = M('articles');
if (!$article_db) {
return fasle;
}
$comment_info = $article_db->where("id = {$id}")->getField('id,comment_sum,comment_addr')[$id];
if (empty($comment_info)) {
return false;
}
$comment_info['comment_sum'] = intval($comment_info['comment_sum']);
//第一条评论则添加评论文件和第一条评论
if (is_null($comment_info['comment_addr'])) {
$comment_path = $this->addCommentFile($id, $article_db);
} else {
$comment_path = C('COMMENT_PATH') . '/' . $comment_info['comment_addr'];
}
//添加第一条评论
$xmldom = new \DOMDocument();
$xmldom->load($comment_path);
//获取根节点
$root = $xmldom->getElementsByTagName('comment')->item(0);
//创建id属性节点
$id_node = $xmldom->createAttribute('id');
//创建Node节点
$node_node = $xmldom->CreateElement('node');
//创建name
$name_node = $xmldom->CreateElement('name');
//创建date节点
$date_node = $xmldom->CreateElement('date');
//创建message节点
$message_node = $xmldom->CreateElement('message');
//节点赋值
$id_node->nodeValue = ++$comment_info['comment_sum'];
$name_node->nodeValue = base64_encode($name);
$date_node->nodeValue = time();
$message_node->nodeValue = base64_encode($conetnt);
//构建逻辑关系
$node_node->appendChild($id_node);
$node_node->appendChild($name_node);
$node_node->appendChild($date_node);
$node_node->appendChild($message_node);
$root->appendChild($node_node);
if ($xmldom->save($comment_path)) {
$article_db->comment_sum = $comment_info['comment_sum'];
$article_db->where("id = {$id}")->save();
return true;
}
}
示例2: getRSS20
protected function getRSS20($returnDOM = false)
{
$doc = new DOMDocument('1.0', $this->encoding);
$doc->formatOutput = true;
$rss = $doc->createElement('rss');
$rss->setAttribute('version', '2.0');
$channel = $doc->createElement('channel');
$title = $doc->createElement('title', $this->title);
$channel->appendChild($title);
$desc = $doc->createElement('description', $this->description);
$channel->appendChild($desc);
$link = $doc->CreateElement('link', $this->linkSelf);
$channel->appendChild($link);
$lastBuildDate = $doc->createElement('lastBuildDate', date('r', $this->lastUpdated));
$channel->appendChild($lastBuildDate);
foreach ($this->items as $i) {
$item = $doc->createElement('item');
$iGuid = $doc->createElement('guid', $i->guid);
$item->appendChild($iGuid);
$iTitle = $doc->createElement('title', $i->title);
$item->appendChild($iTitle);
$iLink = $doc->createElement('link', $i->guid);
$item->appendChild($iLink);
$iPubDate = $doc->createElement('pubDate', date('r', $this->lastUpdated));
$item->appendChild($iPubDate);
$iDesc = $doc->createElement('description', self::XMLEncode($i->content));
$item->appendChild($iDesc);
$channel->appendChild($item);
}
$rss->appendChild($channel);
$doc->appendChild($rss);
return $returnDOM ? $doc : $doc->saveXML();
}
示例3: count
$oPage->add("<div class=\"page_header\">\n");
$oPage->add("<h2>" . MetaModel::GetClassIcon($sClass) . " <span class=\"hilite\">" . Dict::Format('UI:Search:Count_ObjectsOf_Class_Found', count($aObjects), Metamodel::GetName($sClass)) . "</h2>\n");
$oPage->add("</div>\n");
$oBlock = DisplayBlock::FromObjectSet($oSet, 'list');
$oBlock->Display($oPage, $iBlock++);
$oPage->P(' ');
// Some space ?
}
break;
case 'xml':
default:
$oPage->SetContentType('text/xml');
$oObj = MetaModel::GetObject($sClass, $id, true);
// Build the root XML part
$oXmlDoc = new DOMDocument('1.0', 'UTF-8');
$oXmlRoot = $oXmlDoc->CreateElement('root');
$oXmlNode = $oXmlDoc->CreateElement('node');
$oXmlNode->SetAttribute('id', $oObj->GetKey());
$oXmlNode->SetAttribute('obj_class', get_class($oObj));
$oXmlNode->SetAttribute('obj_class_name', htmlspecialchars(MetaModel::GetName(get_class($oObj))));
$oXmlNode->SetAttribute('name', htmlspecialchars($oObj->GetRawName()));
$oXmlNode->SetAttribute('icon', BuildIconPath($oObj->GetIcon(false)));
// Hard coded for the moment
AddNodeDetails($oXmlNode, $oObj);
$oLinks = $oXmlDoc->CreateElement("links");
$oXmlRoot->SetAttribute('position', 'left');
$oXmlRoot->SetAttribute('title', MetaModel::GetRelationDescription($sRelation) . ' ' . htmlspecialchars($oObj->GetRawName()));
IssueLog::Info(__FUNCTION__ . " Rel: {$sRelation}");
GetRelatedObjectsAsXml($oObj, $sRelation, $oLinks, $oXmlDoc, $oXmlNode, 0, $aExcludedClasses);
$oXmlRoot->AppendChild($oXmlNode);
$oXmlDoc->AppendChild($oXmlRoot);
示例4: run
public static function run($r)
{
$pdf = new pts_pdf_template(pts_title(false), 'Test Client Documentation');
$html_doc = new pts_html_template(pts_title(false), 'Test Client Documentation');
$pdf->AddPage();
$pdf->Image(PTS_CORE_STATIC_PATH . 'images/pts-308x160.png', 69, 85, 73, 38, 'PNG', 'http://www.phoronix-test-suite.com/');
$pdf->Ln(120);
$pdf->WriteStatement('www.phoronix-test-suite.com', 'C', 'http://www.phoronix-test-suite.com/');
$pdf->Ln(15);
$pdf->WriteBigHeaderCenter(pts_title(true));
$pdf->WriteHeaderCenter('User Manual');
//$pdf->WriteText($result_file->get_description());
$pts_options = pts_documentation::client_commands_array();
// Write the test options HTML
$dom = new DOMDocument();
$html = $dom->createElement('html');
$dom->appendChild($html);
$head = $dom->createElement('head');
$title = $dom->createElement('title', 'User Options');
$head->appendChild($title);
$html->appendChild($head);
$body = $dom->createElement('body');
$html->appendChild($body);
$p = $dom->createElement('p', 'The following options are currently supported by the Phoronix Test Suite client. A list of available options can also be found by running ');
$em = $dom->createElement('em', 'phoronix-test-suite help.');
$p->appendChild($em);
$phr = $dom->createElement('hr');
$p->appendChild($phr);
$body->appendChild($p);
foreach ($pts_options as $section => &$contents) {
if (empty($contents)) {
continue;
}
$header = $dom->createElement('h1', $section);
$body->appendChild($header);
sort($contents);
foreach ($contents as &$option) {
$sub_header = $dom->createElement('h3', $option[0]);
$em = $dom->CreateElement('em', ' ' . implode(' ', $option[1]));
$sub_header->appendChild($em);
$body->appendChild($sub_header);
$p = $dom->createElement('p', $option[2]);
$body->appendChild($p);
}
}
$dom->saveHTMLFile(PTS_PATH . 'documentation/stubs/00_user_options.html');
// Write the module options HTML
$dom = new DOMDocument();
$html = $dom->createElement('html');
$dom->appendChild($html);
$head = $dom->createElement('head');
$title = $dom->createElement('title', 'Module Options');
$head->appendChild($title);
$html->appendChild($head);
$body = $dom->createElement('body');
$html->appendChild($body);
$p = $dom->createElement('p', 'The following list is the modules included with the Phoronix Test Suite that are intended to extend the functionality of pts-core. Some of these options have commands that can be run directly in a similiar manner to the other Phoronix Test Suite user commands. Some modules are just meant to be loaded directly by adding the module name to the LoadModules tag in ~/.phoronix-test-suite/user-config.xml or via the PTS_MODULES environmental variable. A list of available modules is also available by running ');
$em = $dom->createElement('em', 'phoronix-test-suite list-modules.');
$p->appendChild($em);
$phr = $dom->createElement('hr');
$p->appendChild($phr);
$body->appendChild($p);
foreach (pts_module_manager::available_modules(true) as $module) {
pts_module_manager::load_module($module);
$header = $dom->createElement('h2', pts_module_manager::module_call($module, 'module_name'));
$body->appendChild($header);
$desc = $dom->createElement('p', pts_module_manager::module_call($module, 'module_description'));
$body->appendChild($desc);
$all_options = pts_module_manager::module_call($module, 'user_commands');
if (count($all_options) > 0) {
// $sub_header = $dom->createElement('h3', 'Module Commands');
// $body->appendChild($sub_header);
foreach ($all_options as $key => $option) {
$p = $dom->createElement('p', 'phoronix-test-suite ' . $module . '.' . str_replace('_', '-', $key));
$body->appendChild($p);
}
}
$vars = pts_module_manager::module_call($module, 'module_environmental_variables');
if (is_array($vars) && count($vars) > 0) {
$p = $dom->createElement('p', 'This module utilizes the following environmental variables: ' . implode(', ', $vars) . '.');
$body->appendChild($p);
}
}
$dom->saveHTMLFile(PTS_PATH . 'documentation/stubs/00_zmodule_options.html');
// Write the external dependencies HTML
$dom = new DOMDocument();
$html = $dom->createElement('html');
$dom->appendChild($html);
$head = $dom->createElement('head');
$title = $dom->createElement('title', 'External Dependencies');
$head->appendChild($title);
$html->appendChild($head);
$body = $dom->createElement('body');
$html->appendChild($body);
$p = $dom->createElement('p', 'The Phoronix Test Suite has a feature known as "External Dependencies" where the Phoronix Test Suite can attempt to automatically install some of the test-specific dependencies on supported distributions. If running on a distribution where there is currently no External Dependencies profile, the needed package name(s) are listed for manual installation.');
$body->appendChild($p);
$p = $dom->createElement('p', 'Below are a list of the operating systems that currently have external dependencies support within the Phoronix Test Suite for the automatic installation of needed test files.');
$body->appendChild($p);
$phr = $dom->createElement('hr');
$p->appendChild($phr);
//.........这里部分代码省略.........
示例5: catch
// get list feed for query
$query = new Zend_Gdata_Spreadsheets_ListQuery();
$query->setSpreadsheetKey($spreadhsheet_key);
$query->setWorksheetId($membership_wksht);
} catch (Exception $e) {
die('ERROR: ' . $e->getMessage());
}
// Creates the Document.
$dom = new DOMDocument('1.0', 'UTF-8');
// Creates the root KML element and appends it to the root document.
$node = $dom->createElementNS('http://earth.google.com/kml/2.1', 'kml');
$parNode = $dom->appendChild($node);
// Creates a KML Document element and append it to the KML element.
$dnode = $dom->createElement('Document');
$docNode = $parNode->appendChild($dnode);
$styleNode = $dom->CreateElement('Style');
$styleNode->setAttribute('id', 'yellow');
$iconStyleNode = $dom->CreateElement('IconStyle');
$iconNode = $dom->CreateElement('Icon');
$iconNode->appendChild($dom->CreateElement('href', 'http://maps.google.com/mapfiles/kml/paddle/ylw-blank.png'));
$iconStyleNode->appendChild($iconNode);
$styleNode->appendChild($iconStyleNode);
$docNode->appendChild($styleNode);
$styleNode = $dom->CreateElement('Style');
$styleNode->setAttribute('id', 'purple');
$iconStyleNode = $dom->CreateElement('IconStyle');
$iconNode = $dom->CreateElement('Icon');
$iconNode->appendChild($dom->CreateElement('href', 'http://maps.google.com/mapfiles/kml/paddle/purple-blank.png'));
$iconStyleNode->appendChild($iconNode);
$styleNode->appendChild($iconStyleNode);
$docNode->appendChild($styleNode);
示例6: DOMDocument
<?php
$dom = new DOMDocument('1.0');
$books = $dom->appendchild($dom->CreateElement('books'));
$book = $books->appendchild($dom->CreateElement('book'));
$title = $book->appendchild($dom->createElement('title'));
$title->appendchild($dom->createTextNode('visual studio.net'));
$authar = $books->appendchild($dom->createelement('authar'));
$authar->appendchild($dom->createtextnode('.net'));
$dom->formatoutput = true;
$test1 = $dom->savexml();
$dom->save('exam6.xml');
示例7: DOMDocument
<?php
$songs = json_decode($_POST['jsonstr'], true);
$dom = new DOMDocument();
$dom->load("default.pli");
$songlist = $dom->getElementsByTagName("songList")->item(0);
foreach ($songs as $id => $name) {
$songnode = $dom->CreateElement("song");
$songid = $dom->CreateElement("id");
$songname = $dom->CreateElement("name");
$songid->appendChild($dom->CreateTextNode($id));
$songname->appendChild($dom->CreateTextNode($name));
$songnode->appendChild($songid);
$songnode->appendChild($songname);
$songlist->appendChild($songnode);
}
$dom->save("default.pli");
if (count($songs) == 1) {
echo "Add {$name} Successfully";
} else {
echo "Add Songs Successfully";
}
示例8: DOMDocument
<?php
$url = "http://www.google.cn/music/artist?id=" . $_POST['id'];
$pagedata = file_get_contents($url);
//
//
$reg = "/player_iframe%3Fid%3D(\\w+).*?\">([^<].*?)</";
preg_match_all($reg, $pagedata, $hotsongs, PREG_SET_ORDER);
$dom = new DOMDocument('1.0', 'utf-8');
$playlistNode = $dom->CreateElement("playlist");
$dom->appendChild($playlistNode);
$listnameNode = $dom->CreateElement("listname");
$listnameNode->appendChild($dom->CreateTextNode("temp"));
$playlistNode->appendChild($listnameNode);
$songListNode = $dom->CreateElement("songList");
$playlistNode->appendChild($songListNode);
foreach ($hotsongs as $song) {
$name = html_entity_decode($song[2], ENT_COMPAT, "utf-8");
$songNode = $dom->CreateElement("song");
$songid = $dom->CreateElement("id");
$songname = $dom->CreateElement("name");
$songid->appendChild($dom->CreateTextNode($song[1]));
$songname->appendChild($dom->CreateTextNode($name));
$songNode->appendChild($songid);
$songNode->appendChild($songname);
$songListNode->appendChild($songNode);
}
$dom->save("ownlist/temp.pli");
//
//
preg_match("/(?<=width=\"100%\" align=\"left\">)[^<]+/", $pagedata, $artistname);
示例9: aToObject
/**
* Convert a tag to object tag.
*
* @param \DOMDocument $DOMdoc
*/
protected function aToObject($DOMdoc)
{
$aTags = $DOMdoc->getElementsByTagName('a');
foreach ($aTags as $aTag) {
$object = $DOMdoc->CreateElement('object');
//Copy the file in the archive
$path = $aTag->getAttribute('href');
$file = $this->getFile($path);
$object->setAttribute('data', $file->getResourceNode()->getName());
$object->setAttribute('type', $file->getResourceNode()->getMimeType());
//Creating one table to replace the tags
$elements[] = [$object, $aTag];
}
//Replaces image tag by the object tag
if (!empty($elements)) {
foreach ($elements as $el) {
$el[1]->parentNode->replaceChild($el[0], $el[1]);
}
}
}