当前位置: 首页>>代码示例>>PHP>>正文


PHP DomDocument::createTextNode方法代码示例

本文整理汇总了PHP中DomDocument::createTextNode方法的典型用法代码示例。如果您正苦于以下问题:PHP DomDocument::createTextNode方法的具体用法?PHP DomDocument::createTextNode怎么用?PHP DomDocument::createTextNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DomDocument的用法示例。


在下文中一共展示了DomDocument::createTextNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: DomDocument

 function props_to_xml()
 {
     # make the source xml
     # make doc and root
     $xml = new DomDocument();
     $root = $xml->createElement('request');
     $root->setAttribute('controller', params('controller'));
     $root->setAttribute('action', params('action'));
     $root = $xml->appendChild($root);
     # unpack the props into xml
     foreach ($this->props as $k => $v) {
         # if it will become xml, do that, otherwise make a dumb tag
         if (is_object($v) && method_exists($v, 'to_xml')) {
             $obj_xml = $v->to_xml(array(), true, true);
             $obj_xml = $xml->importNode($obj_xml->documentElement, true);
             $root->appendChild($obj_xml);
         } else {
             $node = $xml->createElement($k);
             if (strpos($v, '<') !== false || strpos($v, '>') !== false || strpos($v, '&') !== false) {
                 $cdata = $xml->createCDATASection($v);
             } else {
                 $cdata = $xml->createTextNode($v);
             }
             $node->appendChild($cdata);
             $node = $root->appendChild($node);
         }
     }
     return $xml;
 }
开发者ID:brysonian,项目名称:Saint,代码行数:29,代码来源:AbstractView.php

示例2: convertArrayToXml

 /**
  * Convert an Array to XML
  * @param string $root_node - name of the root node to be converted
  * @param array $data - array to be converted
  * @throws \Exception
  * @return \DOMNode
  */
 protected function convertArrayToXml($root_node, $data = array())
 {
     if (!$this->isValidTagName($root_node)) {
         throw new \Exception('Array to XML Conversion - Illegal character in element name: ' . $root_node);
     }
     $node = $this->xml->createElement($root_node);
     if (is_scalar($data)) {
         $node->appendChild($this->xml->createTextNode($this->bool2str($data)));
     }
     if (is_array($data)) {
         foreach ($data as $key => $value) {
             $this->current_node_name = $root_node;
             $key = is_numeric($key) ? Inflector::singularize($this->current_node_name) : $key;
             $node->appendChild($this->convertArrayToXml($key, $value));
             unset($data[$key]);
         }
     }
     if (is_object($data)) {
         // Catch toString objects, and datetime. Note Closure's will fall into here
         if (method_exists($data, '__toString')) {
             $node->appendChild($this->xml->createTextNode($data->__toString()));
         } elseif ($data instanceof \DateTime) {
             $node->appendChild($this->xml->createTextNode($data->format(\DateTime::ISO8601)));
         } else {
             throw new \Exception('Invalid data type used in Array to XML conversion. Must be object of \\DateTime or implement __toString()');
         }
     }
     return $node;
 }
开发者ID:leedavis81,项目名称:drest-common,代码行数:36,代码来源:Xml.php

示例3: create_xml_droits

function create_xml_droits($array_section)
{
    $dom_document = new DomDocument("1.0", "UTF-8");
    $dom_document->formatOutput = true;
    $root = $dom_document->createElement("droits");
    $root = $dom_document->appendChild($root);
    foreach ($array_section as $nom_section => $droits) {
        $section = $dom_document->createElement("section");
        $section->setAttribute("name", $nom_section);
        $section = $root->appendChild($section);
        foreach ($droits as $nom_droit => $type_droit) {
            $droit = $dom_document->createElement("droit");
            $droit = $section->appendChild($droit);
            $nom = $dom_document->createElement("name");
            $nom = $droit->appendChild($nom);
            $textNom = $dom_document->createTextNode($nom_droit);
            $textNom = $nom->appendChild($textNom);
            $type = $dom_document->createElement("type");
            $type = $droit->appendChild($type);
            $textType = $dom_document->createTextNode($type_droit);
            $textType = $type->appendChild($textType);
        }
    }
    $dom_document->save(PATH_ROOT . 'inc/droits.xml');
}
开发者ID:shiooooooookun,项目名称:Nouweo_PHP,代码行数:25,代码来源:create_xml_droits.php

示例4: generate

 public static function generate()
 {
     // Там еще в сайтмепе есть приоритетность. Для главной ставим самую высокую, для всех категорий чуть ниже и последняя приоритетность для постов
     //Создает XML-строку и XML-документ при помощи DOM
     $dom = new DomDocument('1.0');
     //добавление корня - <books>
     $urlset = $dom->appendChild($dom->createElement('urlset'));
     $urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
     // Главная страница
     $url = $urlset->appendChild($dom->createElement('url'));
     $loc = $url->appendChild($dom->createElement('loc'));
     $loc->appendChild($dom->createTextNode("http://" . $_SERVER['SERVER_NAME']));
     $priority = $url->appendChild($dom->createElement('priority'));
     $priority->appendChild($dom->createTextNode('1.0'));
     // Категории фото
     $categoryPhoto = CategoryPhoto::find()->all();
     foreach ($categoryPhoto as $category) {
         $url = $urlset->appendChild($dom->createElement('url'));
         $loc = $url->appendChild($dom->createElement('loc'));
         $loc->appendChild($dom->createTextNode("http://" . $_SERVER['SERVER_NAME'] . "/category/photo/" . $category->url));
         $priority = $url->appendChild($dom->createElement('priority'));
         $priority->appendChild($dom->createTextNode('0.7'));
     }
     // Категории видео
     $categoryVideo = Category::find()->all();
     foreach ($categoryVideo as $category) {
         $url = $urlset->appendChild($dom->createElement('url'));
         $loc = $url->appendChild($dom->createElement('loc'));
         $loc->appendChild($dom->createTextNode("http://" . $_SERVER['SERVER_NAME'] . "/category/video/" . $category->url));
         $priority = $url->appendChild($dom->createElement('priority'));
         $priority->appendChild($dom->createTextNode('0.7'));
     }
     // Страницы фото
     $photoCatalog = PhotoCatalog::find()->where('publish = 1')->all();
     foreach ($photoCatalog as $photo) {
         $url = $urlset->appendChild($dom->createElement('url'));
         $loc = $url->appendChild($dom->createElement('loc'));
         $loc->appendChild($dom->createTextNode("http://" . $_SERVER['SERVER_NAME'] . "/photo/" . $photo->category->url . "/" . $photo->url));
         $priority = $url->appendChild($dom->createElement('priority'));
         $priority->appendChild($dom->createTextNode('0.5'));
     }
     // Страницы видео
     $videos = Video::find()->where('publish = 1')->all();
     foreach ($videos as $video) {
         $url = $urlset->appendChild($dom->createElement('url'));
         $loc = $url->appendChild($dom->createElement('loc'));
         $loc->appendChild($dom->createTextNode("http://" . $_SERVER['SERVER_NAME'] . "/video/" . $video->category->url . "/" . $video->url));
         $priority = $url->appendChild($dom->createElement('priority'));
         $priority->appendChild($dom->createTextNode('0.5'));
     }
     //генерация xml
     $dom->formatOutput = true;
     // установка атрибута formatOutput
     // domDocument в значение true
     // save XML as string or file
     //$test1 = $dom->saveXML(); // передача строки в test1
     $dom->save('../web/sitemap.xml');
     // сохранение файла
 }
开发者ID:Romario25,项目名称:porka,代码行数:59,代码来源:SitemapGenerate.php

示例5: createXml

 /**
  * @param $nameRoot - имя корня xml
  * @param $nameBigElement - имя узла в который записываются данные из массива $data
  * @param $data - массив с данными выгружеными из таблицы
  */
 function createXml($nameRoot, $nameBigElement, $data)
 {
     // создает XML-строку и XML-документ при помощи DOM
     $dom = new DomDocument($this->version, $this->encode);
     // добавление корня
     $root = $dom->appendChild($dom->createElement($nameRoot));
     // отбираем названия полей таблицы
     foreach (array_keys($data[0]) as $k) {
         if (is_string($k)) {
             $key[] = $k;
         }
     }
     // формируем элементы с данными
     foreach ($data as $d) {
         //добавление элемента $nameBigElement в корень
         $bigElement = $root->appendChild($dom->createElement($nameBigElement));
         foreach ($key as $k) {
             $element = $bigElement->appendChild($dom->createElement($k));
             $element->appendChild($dom->createTextNode($d[$k]));
         }
     }
     // сохраняем результат в файл
     $dom->save('format/' . $this->nameFile);
     unset($dom);
 }
开发者ID:AlexB2015,项目名称:dz32,代码行数:30,代码来源:XmlGenerate.class.php

示例6: DomDocument

 function __doRequest($request, $location, $action, $version)
 {
     $dom = new DomDocument('1.0', 'UTF-8');
     $dom->preserveWhiteSpace = false;
     $dom->loadXML($request);
     $hdr = $dom->createElement('soapenv:Header');
     $secNode = $dom->createElement("wsse:Security");
     $secNode->setAttribute("soapenv:mustUnderstand", "1");
     $secNode->setAttribute("xmlns:wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
     $usernameTokenNode = $dom->createElement("wsse:UsernameToken");
     $usernameTokenNode->setAttribute("wsu:Id", "UsernameToken-1");
     $usernameTokenNode->setAttribute("xmlns:wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
     $usrNode = $dom->createElement("wsse:Username");
     $usrNode->appendChild($dom->createTextNode(WS_USER));
     $pwdNode = $dom->createElement("wsse:Password");
     $pwdNode->setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
     $pwdNode->appendchild($dom->createTextnode(WS_PWD));
     $usernameTokenNode->appendChild($usrNode);
     $usernameTokenNode->appendChild($pwdNode);
     $secNode->appendChild($usernameTokenNode);
     $hdr->appendChild($secNode);
     $dom->documentElement->insertBefore($hdr, $dom->documentElement->firstChild);
     $request = $dom->saveXML();
     $request = str_replace("SOAP-ENV", "soapenv", $request);
     $request = str_replace("ns1", "cgt", $request);
     $request = str_replace('<?xml version="1.0" encoding="UTF-8"?>', '', $request);
     //  echo "Este es el nuevo XML: " . print_r($request, true);
     return parent::__doRequest($request, $location, $action, $version);
 }
开发者ID:vallejos,项目名称:samples,代码行数:29,代码来源:ContentGatewayBilling.php

示例7: errorHandler

function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
{
    # capture some additional information
    $agent = $_SERVER['HTTP_USER_AGENT'];
    $ip = $_SERVER['REMOTE_ADDR'];
    $referrer = $_SERVER['HTTP_REFERER'];
    $dt = date("Y-m-d H:i:s (T)");
    # grab email info if available
    global $err_email, $err_user_name;
    # use this to email problem to maintainer if maintainer info is set
    if (isset($err_user_name) && isset($err_email)) {
    }
    # Write error message to user with less details
    $xmldoc = new DomDocument('1.0');
    $xmldoc->formatOutput = true;
    # Set root
    $root = $xmldoc->createElement("error_handler");
    $root = $xmldoc->appendChild($root);
    # Set child
    $occ = $xmldoc->createElement("error");
    $occ = $root->appendChild($occ);
    # Write error message
    $child = $xmldoc->createElement("error_message");
    $child = $occ->appendChild($child);
    $fvalue = $xmldoc->createTextNode("Your request has returned an error: " . $errstr);
    $fvalue = $child->appendChild($fvalue);
    $xml_string = $xmldoc->saveXML();
    echo $xml_string;
    # exit request
    exit;
}
开发者ID:oliviervanre,项目名称:GeolocOptinAdhoc,代码行数:31,代码来源:error.inc.php

示例8: breakTopicMetadaOnCharacter

 /**
  * Break the MODS topic element text-node metadata on 
  * the specified character and put into seperate MODS topic elements.
  *
  * @param string $xmlsnippet The initial MODS topic element.
  *
  * @param string $breakOnCharacter The charcter break the string.
  *     The default character is the semicolon ';'.
  *
  * @return string
  *     An XML string containing one or more MODS topic elements.
  */
 public function breakTopicMetadaOnCharacter($xmlsnippet, $breakOnCharacter = ';')
 {
     // Break topic metadata on ; into seperate topic elements.
     $xml = new \DomDocument();
     $xml->loadxml($xmlsnippet, LIBXML_NSCLEAN);
     $topicNode = $xml->getElementsByTagName('topic')->item(0);
     if (!is_object($topicNode)) {
         $xmlstring = $xmlsnippet;
     } else {
         $topictext = $topicNode->nodeValue;
         $topics = explode($breakOnCharacter, $topictext);
         // remove old topic node.
         $topicNodeParent = $topicNode->parentNode;
         $topicNode->parentNode->removeChild($topicNode);
         $subjectNode = $xml->getElementsByTagName($this->topLevelNodeName)->item(0);
         foreach ($topics as $topic) {
             $topic = trim($topic);
             $newtopicElement = $xml->createElement('topic');
             $topictextNode = $xml->createTextNode($topic);
             $newtopicElement->appendChild($topictextNode);
             $subjectNode->appendChild($newtopicElement);
             unset($topictextNode);
             unset($newtopicElement);
         }
         $xmlstring = $xml->saveXML($subjectNode);
     }
     return $xmlstring;
 }
开发者ID:sprklinginfo,项目名称:mik,代码行数:40,代码来源:FilterModsTopic.php

示例9: setList

 /**
  * @param $field
  * @param $value
  * @param $type
  * @param $ns
  *
  * @return $this
  */
 private function setList($field, $value, $type, $ns)
 {
     $result = $this->xpath->query('//rdf:Description/' . $field . '/' . $type . '/rdf:li');
     $parent = null;
     if ($result->length) {
         $parent = $result->item(0)->parentNode;
         // remove child nodes
         for ($i = 0; $i < $result->length; $i++) {
             $parent->removeChild($result->item($i));
         }
     } else {
         // find the RDF description root
         $description = $this->getOrCreateRDFDescription($ns);
         // create the element and the rdf:Alt child
         $node = $this->dom->createElementNS($ns, $field);
         $parent = $this->dom->createElementNS(self::RDF_NS, $type);
         $description->appendChild($node);
         $node->appendChild($parent);
     }
     if (!$value || !is_array($value) && count($value) == 0) {
         // remove element
         $parent->parentNode->parentNode->removeChild($parent->parentNode);
     } else {
         foreach ((array) $value as $item) {
             $node = $this->dom->createElementNS(self::RDF_NS, 'rdf:li');
             $node->appendChild($this->dom->createTextNode($item));
             if ($type == 'rdf:Alt') {
                 $node->setAttribute('xml:lang', 'x-default');
             }
             $parent->appendChild($node);
         }
     }
     $this->hasChanges = true;
     return $this;
 }
开发者ID:dchesterton,项目名称:image,代码行数:43,代码来源:Xmp.php

示例10: build_error_xml

function build_error_xml($error_)
{
    $dom = new DomDocument('1.0', 'utf-8');
    $rootNode = $dom->createElement('error');
    $textNode = $dom->createTextNode($error_);
    $rootNode->appendChild($textNode);
    $dom->appendChild($rootNode);
    return $dom->saveXML();
}
开发者ID:bloveing,项目名称:openulteo,代码行数:9,代码来源:config.php

示例11: templ_option_tree_export_xml

/**
 * Export Table Data
 *
 * @access public
 * @since 1.0.0
 *
 * @param array $options
 * @param string $table_name
 *
 * @return file
 */
function templ_option_tree_export_xml($options, $table_name)
{
    global $wpdb;
    // create doctype
    $dom = new DomDocument("1.0");
    $dom->formatOutput = true;
    header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
    header("Pragma: no-cache ");
    header("Content-Type: text/plain");
    header('Content-Disposition: attachment; filename="theme-options-' . date("Y-m-d") . '.xml"');
    // create root element
    $root = $dom->createElement($table_name);
    $root = $dom->appendChild($root);
    foreach ($options as $value) {
        // create root element
        $child = $dom->createElement('row');
        $child = $root->appendChild($child);
        // ID
        $item = $dom->createElement('id');
        $item = $child->appendChild($item);
        $text = $dom->createTextNode($value->id);
        $text = $item->appendChild($text);
        // Item ID
        $item = $dom->createElement('item_id');
        $item = $child->appendChild($item);
        $text = $dom->createTextNode($value->item_id);
        $text = $item->appendChild($text);
        // Item Title
        $item = $dom->createElement('item_title');
        $item = $child->appendChild($item);
        $text = $dom->createTextNode($value->item_title);
        $text = $item->appendChild($text);
        // Item Description
        $item = $dom->createElement('item_desc');
        $item = $child->appendChild($item);
        $text = $dom->createTextNode($value->item_desc);
        $text = $item->appendChild($text);
        // Item Type
        $item = $dom->createElement('item_type');
        $item = $child->appendChild($item);
        $text = $dom->createTextNode($value->item_type);
        $text = $item->appendChild($text);
        // Item Options
        $item = $dom->createElement('item_options');
        $item = $child->appendChild($item);
        $text = $dom->createTextNode($value->item_options);
        $text = $item->appendChild($text);
        // Item Sort
        $item = $dom->createElement('item_sort');
        $item = $child->appendChild($item);
        $text = $dom->createTextNode($value->item_sort);
        $text = $item->appendChild($text);
    }
    // save and display tree
    echo $dom->saveXML();
    die;
}
开发者ID:annguyenit,项目名称:getdeal,代码行数:68,代码来源:export.php

示例12: getOptions

 private function getOptions($_preferenceName, $_options)
 {
     $preference = $this->_getDefaultBasePreference($_preferenceName);
     $doc = new DomDocument('1.0');
     $options = $doc->createElement('options');
     $doc->appendChild($options);
     foreach ($_options as $opt) {
         $value = $doc->createElement('value');
         $value->appendChild($doc->createTextNode($opt));
         $label = $doc->createElement('label');
         $label->appendChild($doc->createTextNode($opt));
         $option = $doc->createElement('option');
         $option->appendChild($value);
         $option->appendChild($label);
         $options->appendChild($option);
     }
     $preference->options = $doc->saveXML();
     // save first option in pref value
     $preference->value = is_array($_options) && isset($_options[0]) ? $_options[0] : '';
     return $preference;
 }
开发者ID:rodrigofns,项目名称:ExpressoLivre3,代码行数:21,代码来源:Preference.php

示例13: buildMarkdown

 /**
  * Proxy out to the parser and convert HTML node to Markdown node, ignores
  * nodes not in the $markdownable array
  *
  * @param  object $node
  * @return void
  */
 public function buildMarkdown($node)
 {
     if (!isset($this->parsers[$node->nodeName]) && $node->nodeName !== '#text') {
         return;
     }
     if ($node->nodeName === '#text') {
         $markdown = preg_replace('~\\s+~', ' ', $node->nodeValue);
     } else {
         $markdown = $this->parsers[$node->nodeName]->parse($node);
     }
     $markdownNode = $this->doc->createTextNode($markdown);
     $node->parentNode->replaceChild($markdownNode, $node);
 }
开发者ID:progmedia,项目名称:markdownable,代码行数:20,代码来源:Converter.php

示例14: addComment

function addComment($CommentFile, $date_value, $author_value, $subject_value, $msg_value, $ip)
{
    $xml = new DomDocument('1.0', 'utf-8');
    if (file_exists($CommentFile)) {
        $xml->load($CommentFile);
        $root = $xml->firstChild;
    } else {
        $root = $xml->appendChild($xml->createElement("comments"));
    }
    $comment = $xml->createElement("comment");
    $root->appendChild($comment);
    // Add date attribute
    $attr_date = $xml->createAttribute("timestamp");
    $comment->appendChild($attr_date);
    $value = $xml->createTextNode($date_value);
    $attr_date->appendChild($value);
    // Add author attribute
    $attr_author = $xml->createAttribute("author");
    $comment->appendChild($attr_author);
    $value = $xml->createTextNode($author_value);
    $attr_author->appendChild($value);
    // Add author ip address
    $attr_ip = $xml->createAttribute("ip");
    $comment->appendChild($attr_ip);
    $value = $xml->createTextNode($ip);
    $attr_ip->appendChild($value);
    // add subject child node
    $subject = $xml->createElement("subject");
    $comment->appendChild($subject);
    $value = $xml->createTextNode($subject_value);
    $subject->appendChild($value);
    // add message child node
    $msg = $xml->createElement("message");
    $comment->appendChild($msg);
    $value = $xml->createTextNode($msg_value);
    $msg->appendChild($value);
    $xml->save($CommentFile);
    return $xml->getElementsByTagName("comment")->length;
}
开发者ID:loveq369,项目名称:iPaintBundle,代码行数:39,代码来源:add_comment.php

示例15: nl2br

 public function nl2br($var)
 {
     $parts = explode("\n", $var);
     $doc = new \DomDocument();
     $result = [];
     foreach ($parts as $key => $part) {
         $new = $doc->createTextNode($part);
         $result[] = $new;
         if ($key !== count($parts) - 1) {
             $br = $doc->createElement('br');
             $result[] = $br;
         }
     }
     return $result;
 }
开发者ID:solleer,项目名称:framework,代码行数:15,代码来源:Nl2br.php


注:本文中的DomDocument::createTextNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。