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


PHP DOMDocument::save方法代码示例

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


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

示例1: output

 /**
  * @param Result $result
  */
 public function output(Result $result)
 {
     $assumptions = $result->getAssumptions();
     foreach ($assumptions as $assumption) {
         $fileElements = $this->xpath->query('/phpa/files/file[@name="' . $assumption['file'] . '"]');
         if ($fileElements->length === 0) {
             $files = $this->xpath->query('/phpa/files')->item(0);
             $fileElement = $this->document->createElement('file');
             $fileElement->setAttribute('name', $assumption['file']);
             $files->appendChild($fileElement);
         } else {
             $fileElement = $fileElements->item(0);
         }
         $lineElement = $this->document->createElement('line');
         $lineElement->setAttribute('number', $assumption['line']);
         $lineElement->setAttribute('message', $assumption['message']);
         $fileElement->appendChild($lineElement);
     }
     $this->document->documentElement->setAttribute('assumptions', $result->getAssumptionsCount());
     $this->document->documentElement->setAttribute('bool-expressions', $result->getBoolExpressionsCount());
     $this->document->documentElement->setAttribute('percentage', $result->getPercentage());
     $this->document->preserveWhiteSpace = false;
     $this->document->formatOutput = true;
     $this->document->save($this->file);
     $this->cli->out(sprintf('Written %d assumption(s) to file %s', $result->getAssumptionsCount(), $this->file));
 }
开发者ID:rskuipers,项目名称:php-assumptions,代码行数:29,代码来源:XmlOutput.php

示例2: save

 /**
  * Save FB2 file
  * @param string $path
  */
 public function save($path = '')
 {
     if ($this->fictionBook instanceof FictionBook) {
         self::$FB2DOM = new \DOMDocument("1.0", "UTF-8");
         self::$FB2DOM->preserveWhiteSpace = FALSE;
         self::$FB2DOM->formatOutput = TRUE;
         $this->fictionBook->buildXML();
         self::$FB2DOM->schemaValidate("./XSD/FB2.2/FictionBook.xsd");
         //$domDoc->schemaValidate("./XSD/FB2.0/FictionBook2.xsd");
         self::$FB2DOM->save($path);
         echo self::$FB2DOM->saveXML();
     }
 }
开发者ID:head26,项目名称:FictionBookConverter,代码行数:17,代码来源:FB2Builder.php

示例3: createXML

 private function createXML()
 {
     global $Site;
     global $dbPages;
     global $dbPosts;
     global $Url;
     $doc = new DOMDocument('1.0', 'UTF-8');
     // Friendly XML code
     $doc->formatOutput = true;
     // Create urlset element
     $urlset = $doc->createElement('urlset');
     $attribute = $doc->createAttribute('xmlns');
     $attribute->value = 'http://www.sitemaps.org/schemas/sitemap/0.9';
     $urlset->appendChild($attribute);
     // --- Base URL ---
     // Create url, loc and lastmod elements
     $url = $doc->createElement('url');
     $loc = $doc->createElement('loc', $Site->url());
     $lastmod = $doc->createElement('lastmod', '');
     // Append loc and lastmod -> url
     $url->appendChild($loc);
     $url->appendChild($lastmod);
     // Append url -> urlset
     $urlset->appendChild($url);
     // --- Pages and Posts ---
     $all = array();
     $url = trim($Site->url(), '/');
     // --- Pages ---
     $filter = trim($Url->filters('page'), '/');
     $pages = $dbPages->getDB();
     unset($pages['error']);
     foreach ($pages as $key => $db) {
         $permalink = empty($filter) ? $url . '/' . $key : $url . '/' . $filter . '/' . $key;
         $date = Date::format($db['date'], DB_DATE_FORMAT, SITEMAP_DATE_FORMAT);
         array_push($all, array('permalink' => $permalink, 'date' => $date));
     }
     // --- Posts ---
     $filter = rtrim($Url->filters('post'), '/');
     $posts = $dbPosts->getDB();
     foreach ($posts as $key => $db) {
         $permalink = empty($filter) ? $url . '/' . $key : $url . '/' . $filter . '/' . $key;
         $date = Date::format($db['date'], DB_DATE_FORMAT, SITEMAP_DATE_FORMAT);
         array_push($all, array('permalink' => $permalink, 'date' => $date));
     }
     // Generate the XML for posts and pages
     foreach ($all as $db) {
         // Create url, loc and lastmod elements
         $url = $doc->createElement('url');
         $loc = $doc->createElement('loc', $db['permalink']);
         $lastmod = $doc->createElement('lastmod', $db['date']);
         // Append loc and lastmod -> url
         $url->appendChild($loc);
         $url->appendChild($lastmod);
         // Append url -> urlset
         $urlset->appendChild($url);
     }
     // Append urlset -> XML
     $doc->appendChild($urlset);
     $doc->save(PATH_PLUGINS_DATABASES . $this->directoryName . DS . 'sitemap.xml');
 }
开发者ID:bayramlielxan,项目名称:bludit,代码行数:60,代码来源:plugin.php

示例4: saveanswer

function saveanswer($filename, $objectid, $answer, $userid)
{
    if (!file_exists($filename)) {
        file_put_contents($filename, "<?xml version=\"1.0\" ?>\n<responses></responses>");
    }
    libxml_use_internal_errors(true);
    $doc = new DOMDocument();
    $result = $doc->load($filename);
    if (!$result) {
        $message = "";
        foreach (libxml_get_errors() as $error) {
            $message .= $error->message;
            ///$and = "\nand ";
        }
        libxml_clear_errors();
        echo json_encode(array(status => 0, message => "Could not parse data file! Reason: {$message}"));
        exit;
    }
    //$xpath = new DOMXPath($doc);
    $responsenode = $doc->documentElement->appendChild($doc->createElement("response"));
    $responsenode->setAttribute("objectid", $objectid);
    $responsenode->setAttribute("answer", $answer);
    $responsenode->setAttribute("userid", $userid);
    $doc->save($filename);
    echo json_encode(array(status => 1));
}
开发者ID:rbgeplantsman,项目名称:YesNo,代码行数:26,代码来源:saveanswer.php

示例5: createXML

 private function createXML()
 {
     global $Site;
     global $dbPages;
     global $dbPosts;
     global $Url;
     $xml = '<?xml version="1.0" encoding="UTF-8" ?>';
     $xml .= '<rss version="2.0">';
     $xml .= '<channel>';
     $xml .= '<title>' . $Site->title() . '</title>';
     $xml .= '<link>' . $Site->url() . '</link>';
     $xml .= '<description>' . $Site->description() . '</description>';
     $posts = buildPostsForPage(0, 10, true);
     foreach ($posts as $Post) {
         $xml .= '<item>';
         $xml .= '<title>' . $Post->title() . '</title>';
         $xml .= '<link>' . $Post->permalink(true) . '</link>';
         $xml .= '<description>' . $Post->description() . '</description>';
         $xml .= '</item>';
     }
     $xml .= '</channel></rss>';
     // New DOM document
     $doc = new DOMDocument();
     // Friendly XML code
     $doc->formatOutput = true;
     $doc->loadXML($xml);
     $doc->save(PATH_PLUGINS_DATABASES . $this->directoryName . DS . 'rss.xml');
 }
开发者ID:michaelctorres,项目名称:bludit,代码行数:28,代码来源:plugin.php

示例6: __construct

 public function __construct($config)
 {
     $this->_config = $config;
     // Create XML file if not exist
     $filePath = $this->getPath();
     if (!file_exists($filePath)) {
         $arr = explode('/', dirname($filePath));
         $curr = array();
         foreach ($arr as $val) {
             $curr[] = $val;
             $path = implode('/', $curr) . '/';
             if (!file_exists($path)) {
                 mkdir($path, 0777);
                 @chmod($path, 0777);
             }
         }
         $xml = new \DOMDocument();
         $error = $xml->createElement("errors");
         $xml->appendChild($error);
         $xml->formatOutput = true;
         $xml->save($filePath);
         @chmod($filePath, 0777);
     }
     $this->_xml = simplexml_load_file($filePath);
 }
开发者ID:ASAPUK,项目名称:Monitoring,代码行数:25,代码来源:CheckDuplicate.php

示例7: run

 public function run()
 {
     foreach ($this->datasource as $concursoName => $concurso) {
         $xml = new \SimpleXMLElement('<concursos/>');
         foreach ($this->data[$concursoName] as $nrconcurso => $concursoData) {
             $concursoXml = $xml->addChild('concurso');
             $concursoXml->addAttribute('numero', $nrconcurso);
             $concursoXml->addChild('data', $concursoData['data']);
             $dezenas = $concursoXml->addChild('dezenas');
             foreach ($concursoData['dezenas'] as $dezena) {
                 $dezenas->addChild('dezena', $dezena);
             }
             $faixasPremios = $concursoXml->addChild('faixas_premios');
             foreach ($concursoData['faixas_premios'] as $faixa) {
                 $faixasPremios->addChild('faixa', $faixa);
             }
             $concursoXml->addChild('arrecadacao', $concursoData['arrecadacao']);
             $concursoXml->addChild('total_ganhadores', $concursoData['total_ganhadores']);
             $concursoXml->addChild('acumulado', $concursoData['acumulado']);
             $concursoXml->addChild('valor_acumulado', $concursoData['valor_acumulado']);
         }
         $filename = $this->localstorage . $concurso['xml'];
         $dom = new \DOMDocument('1.0');
         $dom->preserveWhiteSpace = false;
         $dom->formatOutput = true;
         $dom->loadXML($xml->asXML());
         $dom->save($filename);
     }
 }
开发者ID:evandrobalmant,项目名称:loteria-api,代码行数:29,代码来源:Writer.php

示例8: cascadenik_svg_compile

function cascadenik_svg_compile($file, $path=null) {
  global $tmp_dir;

  if(!preg_match("/^(.*\/)([^\/]*)$/", $file, $m)) {
    print "Mapnik Rotate: No path found???\n";
    return;
  }
  if(!$path)
    $path=$m[1];
  $nfile="$tmp_dir/$m[2]";

  $dom=new DOMDocument();
  $dom->load($file);

  $list=$dom->getElementsByTagName("Stylesheet");
  for($i=0; $i<$list->length; $i++) {
    $mss_file=$list->item($i)->getAttribute("src");
    cascadenik_svg_process($mss_file, $mss_file, $path);
    $list->item($i)->setAttribute("src", "$tmp_dir/$mss_file");
  }

  $dom->save($nfile);

  $file=$nfile;
}
开发者ID:plepe,项目名称:OpenStreetBrowser,代码行数:25,代码来源:mcp.php

示例9: combineXML

function combineXML($dir, $id)
{
    $dir .= DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'vqmod' . DIRECTORY_SEPARATOR . 'xml';
    $files = is_dir($dir) ? glob($dir . DIRECTORY_SEPARATOR . '*.xml', GLOB_BRACE) : array();
    if (empty($files)) {
        return;
    }
    $modification = <<<XML
<modification>
\t<id>{$id}</id>
\t<version>2.1.0.2</version>
\t<vqmver>2.4.1</vqmver>
\t<author></author>
</modification>
XML;
    $xml = new DOMDocument('1.0', 'UTF-8');
    $xml->formatOutput = true;
    $xml->preserveWhiteSpace = true;
    $xml->loadXml($modification);
    $modification = $xml->getElementsByTagName('modification')->item(0);
    $author = $modification->getElementsByTagName('author')->item(0);
    foreach ($files as $file) {
        $dom = parseXML($file);
        $fileTags = $dom->getElementsByTagName('modification')->item(0)->getElementsByTagName('file');
        $originAutor = $dom->getElementsByTagName('modification')->item(0)->getElementsByTagName('author');
        $author->textContent = $originAutor->item(0)->textContent;
        for ($i = 0; $i < $fileTags->length; $i++) {
            $fileTag = $fileTags->item($i);
            $fileTag = $xml->importNode($fileTag, true);
            $modification->appendChild($fileTag);
        }
        unlink($file);
    }
    $xml->save($dir . DIRECTORY_SEPARATOR . $id . '.xml');
}
开发者ID:dannywly,项目名称:frontend-test,代码行数:35,代码来源:package.php

示例10: createRss

function createRss()
{
    $rss_name = 'rss2.xml';
    $rss_title = "News feed";
    $rss_link = "http://lessons/xml/news.php";
    $dom = new DOMDocument('1.0', 'utf-8');
    $dom->formatOutput = true;
    // с отступами
    $dom->preserveWhiteSpace = false;
    $rss = $dom->createElement('rss');
    //    $rss->setAttribute('version', '2.0');
    $dom->appendChild($rss);
    $channel = $dom->createElement('channel');
    $rss->appendChild($channel);
    $title = $dom->createElement('title', $rss_title);
    $link = $dom->createElement('link', $rss_link);
    $channel->appendChild($title);
    $channel->appendChild($link);
    $item = $dom->createElement('item');
    $iIitle = $dom->createElement('title', 'Item title');
    $iLink = $dom->createElement('link', 'Link to item');
    $iDescription = $dom->createElement('descriptiion', 'Description of item');
    $iPubDate = $dom->createElement('pubDate', 'Publication date');
    $iCategory = $dom->createElement('category', 'News category');
    $item->appendChild($iIitle);
    $item->appendChild($iLink);
    $item->appendChild($iDescription);
    $item->appendChild($iPubDate);
    $item->appendChild($iCategory);
    $channel->appendChild($item);
    $dom->save($rss_name);
}
开发者ID:popovdenis,项目名称:lessons-1,代码行数:32,代码来源:news.php

示例11: resetSalt

 /**
  * Create the salt code
  * A salt code is a random set of bytes of a 
  * fixed length that is added to 
  * the input of a hash algorithm.
  */
 public static function resetSalt()
 {
     $saltpattern = self::createSalt();
     $filename = APPLICATION_PATH . "/configs/config.xml";
     if (file_exists($filename)) {
         $xml = simplexml_load_file($filename);
         if (empty($xml->config->saltpattern)) {
             $config = $xml->config;
             $config->addChild('saltpattern', $saltpattern);
         } else {
             $xml->config->saltpattern = $saltpattern;
         }
         // Get the xml string
         $xmlstring = $xml->asXML();
         // Prettify and save the xml configuration
         $dom = new DOMDocument();
         $dom->loadXML($xmlstring);
         $dom->formatOutput = true;
         $formattedXML = $dom->saveXML();
         // Save the config xml file
         if (@$dom->save(APPLICATION_PATH . "/configs/config.xml")) {
             return true;
         } else {
             throw new Exception("Error on saving the xml file in " . APPLICATION_PATH . "/configs/config.xml <br/>Please check the folder permissions");
         }
     } else {
         throw new Exception('There was a problem to save data in the config.xml file. Permission file problems?');
     }
 }
开发者ID:kokkez,项目名称:shineisp,代码行数:35,代码来源:Hasher.php

示例12: create_xml

function create_xml($data, $keys_array, $filename, $table_name)
{
    $names = array('categories' => 'category', 'comp_orders' => 'comp_order', 'orders' => 'order', 'products' => 'product', 'statuses' => 'status', 'users' => 'user');
    // Создаем DOM документ
    $xml = new DOMDocument('1.0', 'UTF-8');
    $xml->formatOutput = true;
    // Создаем корневой элемент
    $loft_shop = $xml->createElement("loft_shop");
    $xml->appendChild($loft_shop);
    // Создаем список
    $elements = $xml->createElement($table_name);
    $loft_shop->appendChild($elements);
    foreach ($data as $item) {
        // Создаем элемент списка
        $element = $xml->createElement($names[$table_name]);
        $id = $xml->createAttribute("id");
        $id->value = $item['id'];
        // Устанавливаем атрибут id
        $element->appendChild($id);
        for ($i = 1; $i < count($keys_array); $i++) {
            $xml_field = $xml->createElement($keys_array[$i], $item[$keys_array[$i]]);
            $element->appendChild($xml_field);
        }
        $elements->appendChild($element);
    }
    $xml->save($filename);
}
开发者ID:Antoshka007,项目名称:php_dz3.2,代码行数:27,代码来源:functions.php

示例13: addCustomerToIndex

function addCustomerToIndex($customerId)
{
    $indexDoc = simplexml_load_file('customer-index.xml');
    $lastValue = $indexDoc->lastIndex;
    $lastValue = $lastValue + 1;
    $dom = new DOMDocument();
    $dom->load("customer-index.xml");
    $value = '2290000000' . $lastValue;
    $dom->getElementsByTagName('lastIndex')->item(0)->nodeValue = $lastValue;
    //update the last value
    //$doc->getElementsByTagName("title")->item(0)->nodeValue = $titleText;
    $customerElement = $dom->createElement('customer');
    //createNode($dom, $dom->customers,'customer');
    $custIdAttr = $dom->createAttribute('customer_id');
    $custIdVal = $dom->createTextNode($customerId);
    $custIdAttr->appendChild($custIdVal);
    $customerElement->appendChild($custIdAttr);
    $suIdAttr = $dom->createAttribute('cust_sid');
    $suIdVal = $dom->createTextNode($value);
    $suIdAttr->appendChild($suIdVal);
    $customerElement->appendChild($suIdAttr);
    $dom->getElementsByTagName('customers')->item(0)->appendChild($customerElement);
    $dom->save('customer-index.xml');
    return $value;
}
开发者ID:ahmedOpeyemi,项目名称:retailpro_magento_integration,代码行数:25,代码来源:customer.php

示例14: execute

 public function execute(InputInterface $input, OutputInterface $output)
 {
     $session = $this->get('phpcr.session');
     $file = $input->getArgument('file');
     $pretty = $input->getOption('pretty');
     $exportDocument = $input->getOption('document');
     $dialog = $this->get('helper.question');
     if (file_exists($file)) {
         $confirmed = true;
         if (false === $input->getOption('no-interaction')) {
             $confirmed = $dialog->ask($input, $output, new ConfirmationQuestion('File already exists, overwrite?'));
         }
         if (false === $confirmed) {
             return;
         }
     }
     $stream = fopen($file, 'w');
     $absPath = $input->getArgument('absPath');
     PathHelper::assertValidAbsolutePath($absPath);
     if (true === $exportDocument) {
         $session->exportDocumentView($absPath, $stream, $input->getOption('skip-binary'), $input->getOption('no-recurse'));
     } else {
         $session->exportSystemView($absPath, $stream, $input->getOption('skip-binary'), $input->getOption('no-recurse'));
     }
     fclose($stream);
     if ($pretty) {
         $xml = new \DOMDocument(1.0);
         $xml->load($file);
         $xml->preserveWhitespace = true;
         $xml->formatOutput = true;
         $xml->save($file);
     }
 }
开发者ID:phpcr,项目名称:phpcr-shell,代码行数:33,代码来源:SessionExportCommand.php

示例15: merge

 public function merge()
 {
     /**
     * 	7. xl/workbook.xml
     		=> add
     		<sheet name="{New sheet}" sheetId="{N}" r:id="rId{N}"/>
     */
     $filename = "{$this->result_dir}/xl/workbook.xml";
     $dom = new \DOMDocument();
     $dom->load($filename);
     $xpath = new \DOMXPath($dom);
     $xpath->registerNamespace("m", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
     $elems = $xpath->query("//m:sheets");
     foreach ($elems as $e) {
         $tag = $dom->createElement('sheet');
         $tag->setAttribute('name', $this->sheet_name);
         $tag->setAttribute('sheetId', $this->sheet_number);
         $tag->setAttribute('r:id', "rId" . $this->sheet_number);
         $e->appendChild($tag);
         break;
     }
     // make sure all worksheets have the correct rId - we might have assigned them new ids
     // in the Tasks\WorkbookRels::merge() method
     $elems = $xpath->query("//m:sheets/m:sheet");
     foreach ($elems as $e) {
         $e->setAttribute("r:id", "rId" . $e->getAttribute("sheetId"));
     }
     $dom->save($filename);
 }
开发者ID:infostreams,项目名称:excel-merge,代码行数:29,代码来源:Workbook.php


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