本文整理汇总了PHP中DOMDocument::createTextNode方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMDocument::createTextNode方法的具体用法?PHP DOMDocument::createTextNode怎么用?PHP DOMDocument::createTextNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::createTextNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$container = $this->getContainer();
$contentLoaderService = $container->get('blend_ez_sitemap.content');
$locations = $contentLoaderService->loadLocations();
$sitemap = new \DOMDocument('1.0', 'utf-8');
$sitemap->preserveWhiteSpace = false;
$sitemap->formatOutput = true;
$urlSet = $sitemap->createElement('urlset');
$sitemap->appendChild($urlSet);
// add url blocks to sitemap xml
// <url>
// <loc>/</loc>
// <lastmod>2015-06-15</lastmod>
// </url>
foreach ($locations as $location) {
// create url block
$urlBlock = $sitemap->createElement('url');
$urlSet->appendChild($urlBlock);
// create loc tag
$loc = $sitemap->createElement('loc');
$urlBlock->appendChild($loc);
$url = $container->get('router')->generate($location);
$locText = $sitemap->createTextNode($url);
$loc->appendChild($locText);
// create lastmod tag
$lastmod = $sitemap->createElement('lastmod');
$urlBlock->appendChild($lastmod);
$lastmodText = $sitemap->createTextNode($location->contentInfo->modificationDate->format('Y-m-d'));
$lastmod->appendChild($lastmodText);
}
$fp = fopen('web/sitemap.xml', 'w');
fwrite($fp, $sitemap->saveXml());
fclose($fp);
}
示例2: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$file = $input->getArgument('file');
if (!preg_match("'^/|(?:[^:\\\\/]+://)|(?:[a-z]:[\\\\/])'i", $file)) {
$file = $this->directory . '/resource/' . $file . '.html.xml';
}
$file = Filesystem::normalizePath($file);
$questionHelper = $this->getHelper('question');
$question = new ConfirmationQuestion(sprintf('Create view <info>%s</info>? [n] ', $file), false);
if (!$questionHelper->ask($input, $output, $question)) {
return;
}
$xml = new \DOMDocument('1.0', 'UTF-8');
$xml->formatOutput = true;
$root = $xml->appendChild($xml->createElementNS(ExpressViewParser::NS_EXPRESS, 'k:composition'));
$root->appendChild($xml->createAttribute('extends'));
$root->appendChild($xml->createAttribute('xmlns'))->appendChild($xml->createTextNode(ExpressViewParser::NS_XHTML));
$root->appendChild($xml->createTextNode("\n\n "));
$block = $root->appendChild($xml->createElementNS(ExpressViewParser::NS_EXPRESS, 'k:block'));
$block->appendChild($xml->createAttribute('name'))->appendChild($xml->createTextNode('main'));
$block->appendChild($xml->createTextNode("\n TODO: Create composition contents...\n "));
$root->appendChild($xml->createTextNode("\n\n"));
Filesystem::writeFile($file, $xml->saveXML());
$output->writeln('');
$output->writeln(sprintf('CREATED: <info>%s</info>', $file));
}
示例3: DOMElement
/**
* 生成DOMElement树
* array(
* 'tagName'=>'Shanghai', // 标签名称
* 'nodeValue'=>'', // 标签值,可选
* 'attributeArr'=>array(), // 属性值, 可选
* 'subElementArr'=>array( // 子节点,跟父类数据结构一样,可选
* array(
* 'tagName'=>'Hongkou',
* 'nodeValue'=>'Hongkou nodeValue',
* 'attributeArr'=>array('lng'=>'100', 'lat'=>'300'),
* 'subElementArr'=>array(),
* ),
* array(
* 'tagName'=>'Xuhui',
* 'nodeValue'=>'Xuhui nodeValue',
* 'attributeArr'=>array('lng'=>'200', 'lat'=>'400'),
* 'subElementArr'=>array(),
* ),
* ),
* );
* @param DOMDocument $DOMDocument 用于生成中间环节的DOMElement,DOMText,DOMAttr等,直接new DOMElement会出现不可写的报错
* @param Array $arr
*/
public static function DOMElement(DOMDocument $DOMDocument, $arr)
{
$DOMElement = $DOMDocument->createElement($arr['tagName']);
$DOMDocument->appendChild($DOMElement);
if (!empty($arr['nodeValue'])) {
// 如果存在节点文本,则添加该文本
$textNode = $DOMDocument->createTextNode($arr['nodeValue']);
$DOMElement->appendChild($textNode);
}
if (!empty($arr['attributeArr'])) {
// 如果存在属性,则循环为当前标签添加属性
foreach ($arr['attributeArr'] as $k => $v) {
$attribute = $DOMDocument->createAttribute($k);
$attribute->appendChild($DOMDocument->createTextNode($v));
$DOMElement->appendChild($attribute);
}
}
if (!empty($arr['subElementArr'])) {
// 如果存在子节点,则循环追加子节点
foreach ($arr['subElementArr'] as $subElement) {
$DOMElement->appendChild(self::DOMElement($DOMDocument, $subElement));
}
}
return $DOMElement;
}
示例4: addCommonNodesToContentDom
/**
* @param \DOMDocument $dom
* @param \DOMElement $productNode
* @param Product $product
*/
protected function addCommonNodesToContentDom($dom, \DOMElement $productNode, Product $product)
{
$productIdNode = $dom->createElement("id", $product->getProductId());
$productNode->appendChild($productIdNode);
$storeIdNode = $dom->createElement("storeid", $product->getStoreId());
$productNode->appendChild($storeIdNode);
$languageNode = $dom->createElement("language", $product->getLanguage());
$productNode->appendChild($languageNode);
$availabilityNode = $dom->createElement("availability", $product->getAvailability() ? 1 : 0);
$productNode->appendChild($availabilityNode);
$skuNode = $dom->createElement("sku", $product->getSku());
$productNode->appendChild($skuNode);
$titleNode = $dom->createElement("title");
$titleValueTextNode = $dom->createTextNode($product->getTitle());
$titleNode->appendChild($titleValueTextNode);
$productNode->appendChild($titleNode);
$descriptionNode = $dom->createElement("description");
$descriptionValueTextNode = $dom->createTextNode($product->getDescription());
$descriptionNode->appendChild($descriptionValueTextNode);
$productNode->appendChild($descriptionNode);
$shortDescriptionNode = $dom->createElement("short_description");
$shortDescriptionValueTextNode = $dom->createTextNode($product->getShortDescription());
$shortDescriptionNode->appendChild($shortDescriptionValueTextNode);
$productNode->appendChild($shortDescriptionNode);
$priceNode = $dom->createElement("price", number_format($product->getPrice(), 2));
$productNode->appendChild($priceNode);
$specialPriceNode = $dom->createElement("special_price", number_format($product->getSpecialPrice(), 2));
$productNode->appendChild($specialPriceNode);
$groupPriceNode = $dom->createElement("group_price", number_format($product->getGroupPrice(), 2));
$productNode->appendChild($groupPriceNode);
$imageLink = $dom->createElement("image_link", $product->getImageLink());
$productNode->appendChild($imageLink);
}
示例5: Write
function Write($title1, $title2, $author1, $author2, $publisher1, $publisher2)
{
$books = array();
$books[] = array('title' => $title1, 'author' => $author1, 'publisher' => $publisher1);
$books[] = array('title' => $title2, 'author' => $author2, 'publisher' => $publisher2);
$dom = new DOMDocument();
$dom->formatOutput = true;
$r = $dom->createElement("books");
$dom->appendChild($r);
foreach ($books as $book) {
$b = $dom->createElement("book");
$author = $dom->createElement("author");
$author->appendChild($dom->createTextNode($book['author']));
$b->appendChild($author);
$title = $dom->createElement("title");
$title->appendChild($dom->createTextNode($book['title']));
$b->appendChild($title);
$publisher = $dom->createElement("publisher");
$publisher->appendChild($dom->createTextNode($book['publisher']));
$b->appendChild($publisher);
$r->appendChild($b);
}
global $diretorio;
$fileSave = rand(100000000, 900000000) . ".xml";
$dir_fileSave = $diretorio . $fileSave;
$fp = fopen($dir_fileSave, "a");
$escreve = fwrite($fp, $dom->saveXML());
fclose($fp);
echo "<div style='min-height:100px;background-color:rgba(255,255,255,0.2);margin-top:15px;padding:5px;border:1px solid gray;margin-bottom:15px;'>";
echo "<div style='font-weight:bold;color:yellow;'>Xml gerado com sucesso!<br/>Nome do arquivo: {$fileSave}</div>";
echo "<pre style='color:yellow;'>" . $dom->saveXML() . "</pre>";
echo "</div>";
}
示例6: render
public function render($caption_set, $file = false)
{
$dom = new \DOMDocument("1.0");
$dom->formatOutput = true;
$root = $dom->createElement('tt');
$dom->appendChild($root);
$body = $dom->createElement('body');
$root->appendChild($body);
$xmlns = $dom->createAttribute('xmlns');
$xmlns->appendChild($dom->createTextNode('http://www.w3.org/ns/ttml'));
$root->appendChild($xmlns);
$div = $dom->createElement('div');
$body->appendChild($div);
foreach ($caption_set->captions() as $index => $caption) {
$entry = $dom->createElement('p');
$from = $dom->createAttribute('begin');
$from->appendChild($dom->createTextNode(DfxpHelper::time_to_string($caption->start())));
$entry->appendChild($from);
$to = $dom->createAttribute('end');
$to->appendChild($dom->createTextNode(DfxpHelper::time_to_string($caption->end())));
$entry->appendChild($to);
$entry->appendChild($dom->createCDATASection($caption->text()));
$div->appendChild($entry);
}
if ($file) {
return file_put_contents($file, $dom->saveXML());
} else {
return $dom->saveHTML();
}
}
示例7: render
function render()
{
$dom = new DOMDocument("1.0");
$root = $dom->createElement("gpx");
$dom->appendChild($root);
$creator = $dom->createAttribute("createor");
$version = $dom->createAttribute("version");
$version_value = $dom->createTextNode("1.0");
$version->appendChild($version_value);
$root->appendChild($creator);
$root->appendChild($version);
$trk = $dom->createElement("trk");
$root->appendChild($trk);
$trkseg = $dom->createElement("trkseg");
$trk->appendChild($trkseg);
/* Create the items */
foreach ($this->data as $point) {
$trkpt = $dom->createElement("trkpt");
foreach ($point as $key => $value) {
$attribute = $dom->createAttribute($key);
$text = $dom->createTextNode($value);
$attribute->appendChild($text);
$trkpt->appendChild($attribute);
}
$trkseg->appendChild($trkpt);
}
header("Content-type: text/xml");
return $dom->saveXML();
}
示例8: empty_news_xml
private static function empty_news_xml($version, $encoding) {
$newdoc = new DOMDocument($version, $encoding);
/* rss wrapper section */
$root = $newdoc->createElement('rss');
$newdoc->appendChild($root);
$version = $newdoc->createAttribute('version');
$version->appendChild($newdoc->createTextNode('2.0'));
$root->appendChild($version);
$channel = $newdoc->createElement('channel');
$root = $root->appendChild($channel);
$title = $newdoc->createElement('title');
$channel->appendChild($title);
$link = $newdoc->createElement('link');
$channel->appendChild($link);
$link->appendChild($newdoc->createTextNode('http://web.mit.edu/newsoffice'));
$description = $newdoc->createElement('description');
$channel->appendChild($description);
return $newdoc;
}
示例9: geraXML
function geraXML()
{
$this->Id = 'ID' . $this->cUF . $this->CNPJ . $this->mod . $this->serie . $this->nNFIni . $this->nNFFin;
$dom = new DOMDocument('1.0', 'utf-8');
$dom->formatOutput = false;
$DP01 = $dom->appendChild($dom->createElement('inutNFe'));
$DP01_att1 = $DP01->appendChild($dom->createAttribute('versao'));
$DP01_att1->appendChild($dom->createTextNode($this->versao));
$DP01_att2 = $DP01->appendChild($dom->createAttribute('xmlns'));
$DP01_att2->appendChild($dom->createTextNode('http://www.portalfiscal.inf.br/nfe'));
$DP03 = $DP01->appendChild($dom->createElement('infInut'));
$DP04 = $DP03->setAttribute('Id', $this->Id);
$DP05 = $DP03->appendChild($dom->createElement('tpAmb', $this->tpAmb));
$DP06 = $DP03->appendChild($dom->createElement('xServ', $this->xServ));
$DP07 = $DP03->appendChild($dom->createElement('cUF', $this->cUF));
$DP08 = $DP03->appendChild($dom->createElement('ano', $this->ano));
$DP09 = $DP03->appendChild($dom->createElement('CNPJ', $this->CNPJ));
$DP10 = $DP03->appendChild($dom->createElement('mod', $this->mod));
$DP11 = $DP03->appendChild($dom->createElement('serie', $this->serie));
$DP12 = $DP03->appendChild($dom->createElement('nNFIni', $this->nNFIni));
$DP13 = $DP03->appendChild($dom->createElement('nNFFin', $this->nNFFin));
$DP14 = $DP03->appendChild($dom->createElement('xJust', $this->xJust));
$xml = $dom->saveXML();
$assinatura = new assinatura();
$this->XML = $assinatura->assinaXML($xml, 'infInut');
return $this->XML;
}
示例10: generateIndex
public function generateIndex()
{
// Create dom object
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
$dom->substituteEntities = false;
// Create <urlset> root tag
$sitemapindex = $dom->createElement('sitemapindex');
// Add attribute of urlset
$xmlns = $dom->createAttribute('xmlns');
$sitemapindexText = $dom->createTextNode('http://www.sitemaps.org/schemas/sitemap/0.9');
$sitemapindex->appendChild($xmlns);
$xmlns->appendChild($sitemapindexText);
foreach ($this->generators as $generator) {
$sitemap = $dom->createElement('sitemap');
$loc = $dom->createElement('loc');
$loc->appendChild($dom->createTextNode($generator->getWebFilePath()));
$sitemap->appendChild($loc);
$lastmod = $dom->createElement('lastmod');
$lastmod->appendChild($dom->createTextNode(date('Y-m-d')));
$sitemap->appendChild($lastmod);
$sitemapindex->appendChild($sitemap);
}
$dom->appendChild($sitemapindex);
return $dom->save($this->config['file_path']);
}
示例11: format
public function format(array $messages)
{
$dom = new \DOMDocument('1.0', 'utf-8');
$dom->formatOutput = true;
$xliff = $dom->appendChild($dom->createElement('xliff'));
$xliff->setAttribute('version', '1.2');
$xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');
$xliffFile = $xliff->appendChild($dom->createElement('file'));
$xliffFile->setAttribute('source-language', $this->source);
$xliffFile->setAttribute('datatype', 'plaintext');
$xliffFile->setAttribute('original', 'file.ext');
$xliffBody = $xliffFile->appendChild($dom->createElement('body'));
$id = 1;
foreach ($messages as $source => $target) {
$trans = $dom->createElement('trans-unit');
$trans->setAttribute('id', $id);
$s = $trans->appendChild($dom->createElement('source'));
$s->appendChild($dom->createTextNode($source));
$t = $trans->appendChild($dom->createElement('target'));
$t->appendChild($dom->createTextNode($target));
$xliffBody->appendChild($trans);
$id++;
}
return $dom->saveXML();
}
示例12: actionMap
public function actionMap()
{
Yii::$app->response->format = Response::FORMAT_RAW;
$headers = Yii::$app->response->headers;
$headers->add('Content-Type', 'text/xml');
$dom = new \DOMDocument("1.0", "utf-8");
$root = $dom->createElement("urlset");
$root->setAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
$dom->appendChild($root);
$categories = Category::findAll(['is_active' => 1]);
$articles = Article::findAll(['is_active' => 1]);
$items = array_merge($categories, $articles);
foreach ($items as $item) {
$url = $dom->createElement("url");
$loc = $dom->createElement("loc");
if ($item instanceof Article) {
$loc->appendChild($dom->createTextNode(Url::to(['article/view', 'id' => $item->id], true)));
} else {
$loc->appendChild($dom->createTextNode(Url::to(['category/view', 'id' => $item->id], true)));
}
$lastmod = $dom->createElement("lastmod");
$lastmod->appendChild($dom->createTextNode($item->timestamp));
$changefreq = $dom->createElement("changefreq");
$changefreq->appendChild($dom->createTextNode("monthly"));
$priority = $dom->createElement("priority");
$priority->appendChild($dom->createTextNode("0.5"));
$url->appendChild($loc);
$url->appendChild($lastmod);
$url->appendChild($changefreq);
$url->appendChild($priority);
$root->appendChild($url);
}
return $dom->saveXML();
}
示例13: render
/**
* Create a representation of this object in the given media type.
*
* @param $mediaType The media (MIME) type to produce a representation in.
* @return mixed A scalar value.
*/
public function render($mediaType)
{
if ($mediaType != 'application/xml') {
throw new \Exception('Cannot process anything other than application/xml');
}
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
$root = $dom->createElement('Users');
$root = $dom->appendChild($root);
foreach ($this->_getUsers() as $userInfo) {
$user = $dom->createElement('User');
$user = $root->appendChild($user);
$userId = $dom->createElement('ID');
$userId = $user->appendChild($userId);
$text = $dom->createTextNode($userInfo['id']);
$text = $userId->appendChild($text);
$fName = $dom->createElement('FirstName');
$fName = $user->appendChild($fName);
$text = $dom->createTextNode($userInfo['fname']);
$text = $fName->appendChild($text);
$lName = $dom->createElement('LastName');
$lName = $user->appendChild($lName);
$text = $dom->createTextNode($userInfo['lname']);
$text = $lName->appendChild($text);
}
return $dom->saveXML();
}
示例14: fire
/**
*
* @param string $event
* @param Array $params
* @param mixed content $object
* @return Void
*/
public function fire($event, $params, &$object)
{
$default = ['usr_id' => null, 'lst' => '', 'ssttid' => '', 'dest' => '', 'reason' => ''];
$params = array_merge($default, $params);
$dom_xml = new DOMDocument('1.0', 'UTF-8');
$dom_xml->preserveWhiteSpace = false;
$dom_xml->formatOutput = true;
$root = $dom_xml->createElement('datas');
$lst = $dom_xml->createElement('lst');
$ssttid = $dom_xml->createElement('ssttid');
$dest = $dom_xml->createElement('dest');
$reason = $dom_xml->createElement('reason');
$lst->appendChild($dom_xml->createTextNode($params['lst']));
$ssttid->appendChild($dom_xml->createTextNode($params['ssttid']));
$dest->appendChild($dom_xml->createTextNode($params['dest']));
$reason->appendChild($dom_xml->createTextNode($params['reason']));
$root->appendChild($lst);
$root->appendChild($ssttid);
$root->appendChild($dest);
$root->appendChild($reason);
$dom_xml->appendChild($root);
$datas = $dom_xml->saveXml();
$mailed = false;
if ($this->shouldSendNotificationFor($params['usr_id'])) {
if (parent::email()) {
$mailed = true;
}
}
$this->broker->notify($params['usr_id'], __CLASS__, $datas, $mailed);
return;
}
示例15: explode
/**
* This function is used to add quickly a DOMElement into another one
*
* @param DOMDocument $dom The xml document currently considered
* @param DOMElement $nodeToAdd The dom element wherein the new dom node will be added
* @param String $markupAndAttribute The specification of the new dom node
* @param String $textContent Allow to add a textual content within the new node if needed
*
* Here is an inline example:
* $newDomElement = xa($doc, $parentNode, 'newMarkupName'.xs.'param1=val1'.xs.'param2=val2', 'myTextContent');
*
* @return DOMElement The reference to the new created dom element
*/
function &xa(&$dom, &$nodeToAdd, $markupAndAttribute, $textContent = '')
{
$tab = explode(xs, $markupAndAttribute);
$markup = trim($tab[0]);
unset($tab[0]);
$attributes = array();
foreach ($tab as $attAndValue) {
if (!empty($attAndValue)) {
list($attName, $attValue) = explode('=', $attAndValue);
$attributes[$attName] = $attValue;
}
}
$markupElt = $dom->createElement($markup);
if (is_array($attributes)) {
foreach ($attributes as $name => $value) {
$att = $dom->createAttribute($name);
$markupElt->appendChild($att);
$attValue = $dom->createTextNode($value);
$att->appendChild($attValue);
}
}
$nodeToAdd->appendChild($markupElt);
if (!empty($textContent) || $textContent === '0') {
$txt = $dom->createTextNode($textContent);
$markupElt->appendChild($txt);
}
return $markupElt;
}