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


PHP DOMDocument::saveXml方法代码示例

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


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

示例1: __toString

 public function __toString()
 {
     $string = '';
     $dom = new DOMDocument();
     $dom->preserveWhiteSpace = FALSE;
     $dom->formatOutput = TRUE;
     $string .= '<pre>';
     $string .= 'Exception: ' . $this->getMessage() . '<br><br><br><br>';
     $string .= 'If you think there is a bug in SimpleCalDAV, please report the following information on github or send it at palm.michael@gmx.de.<br><br><br>';
     $string .= '<br>For debugging purposes:<br>';
     $string .= '<br>last request:<br><br>';
     $string .= $this->requestHeader;
     if (!empty($this->requestBody)) {
         if (!preg_match('#^Content-type:.*?text/calendar.*?$#', $this->requestHeader, $matches)) {
             $dom->loadXML($this->requestBody);
             $string .= htmlentities($dom->saveXml());
         } else {
             $string .= htmlentities($this->requestBody) . '<br><br>';
         }
     }
     $string .= '<br>last response:<br><br>';
     $string .= $this->responseHeader;
     if (!empty($this->responseBody)) {
         if (!preg_match('#^Content-type:.*?text/calendar.*?$#', $this->responseHeader, $matches)) {
             $dom->loadXML($this->responseBody);
             $string .= htmlentities($dom->saveXml());
         } else {
             $string .= htmlentities($this->responseBody);
         }
     }
     $string .= '<br><br>';
     $string .= 'Trace:<br><br>' . $this->getTraceAsString();
     $string .= '</pre>';
     return $string;
 }
开发者ID:macrotux,项目名称:simplecaldav,代码行数:35,代码来源:CalDAVException.php

示例2: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $buildNumber = $input->getArgument('buildnumber');
     $screenshotsRegex = $input->getArgument('screenshotsRegex');
     if (empty($buildNumber)) {
         throw new \InvalidArgumentException('Missing build number.');
     }
     $urlBase = sprintf('http://builds-artifacts.piwik.org/ui-tests.master/%s', $buildNumber);
     $diffviewer = Http::sendHttpRequest($urlBase . "/screenshot-diffs/diffviewer.html", $timeout = 60);
     $diffviewer = str_replace('&', '&amp;', $diffviewer);
     $dom = new \DOMDocument();
     $dom->loadHTML($diffviewer);
     foreach ($dom->getElementsByTagName("tr") as $row) {
         $columns = $row->getElementsByTagName("td");
         $nameColumn = $columns->item(0);
         $processedColumn = $columns->item(3);
         $testPlugin = null;
         if ($nameColumn && preg_match("/\\(for ([a-zA-Z_]+) plugin\\)/", $dom->saveXml($nameColumn), $matches)) {
             $testPlugin = $matches[1];
         }
         $file = null;
         if ($processedColumn && preg_match("/href=\".*\\/(.*)\"/", $dom->saveXml($processedColumn), $matches)) {
             $file = $matches[1];
         }
         if ($file !== null && preg_match("/" . $screenshotsRegex . "/", $file)) {
             if ($testPlugin == null) {
                 $downloadTo = "tests/PHPUnit/UI/expected-ui-screenshots/{$file}";
             } else {
                 $downloadTo = "plugins/{$testPlugin}/tests/UI/expected-ui-screenshots/{$file}";
             }
             $output->write("<info>Downloading {$file} to .{$downloadTo}...</info>\n");
             Http::sendHttpRequest("{$urlBase}/processed-ui-screenshots/{$file}", $timeout = 60, $userAgent = null, PIWIK_DOCUMENT_ROOT . "/" . $downloadTo);
         }
     }
 }
开发者ID:carriercomm,项目名称:piwik,代码行数:35,代码来源:SyncUITestScreenshots.php

示例3: create_json_file

function create_json_file($doc_url, $file_name)
{
    //Get the file
    $string = file_get_contents($doc_url) or die("Could not open {$doc_url} for reading");
    //Deal with character encoding
    $string = mb_convert_encoding($string, 'utf-8', mb_detect_encoding($string));
    // if you have not escaped entities use
    $file = mb_convert_encoding($string, 'html-entities', 'utf-8');
    //Set up DOMDocument
    $doc = new DOMDocument('1.0', 'UTF-8');
    $doc->substituteEntities = TRUE;
    $doc->loadHTML($file);
    $paragraphs = $doc->getElementsByTagName('p');
    //Initialize variables
    $output = array('chapters' => array());
    $heading = 0;
    //Counter.
    foreach ($paragraphs as $paragraph) {
        $elementValue = $doc->saveXml($paragraph);
        if (!empty($elementValue)) {
            /*
            	Get the attribute
            	If it has "subtitle", wrap it in h2 tags.
            	If it's wrapped in curly braces, convert to php array to describe art.
            	If it doesn't, wrap it in a p tag.
            	Put in JSON array.
            */
            if (stripos($paragraph->getAttribute('class'), 'subtitle')) {
                $heading++;
                $output['chapters'][$heading] = array('heading' => $paragraph->nodeValue, 'content' => array(), 'preview image' => '', 'short title' => '');
            } elseif (stripos($paragraph->nodeValue, '{') !== FALSE) {
                //This is a rich media asset
                //A heading should be set when it triggered a earlier in this loop.
                $clean_string = str_replace("“", "\"", $paragraph->nodeValue);
                $clean_string = str_replace("”", "\"", $clean_string);
                $rich_media = json_decode($clean_string);
                if (is_null($rich_media)) {
                    die('There is a parse error with your rich media: ' . var_dump($clean_string));
                }
                if (is_null($rich_media->filename) || is_null($rich_media->filetype)) {
                    die('Your rich media is missing attributes. ' . var_dump($clean_string));
                }
                //Provides some basic validation.
                $output['chapters'][$heading]['content'][] = array('filename' => $rich_media->filename, 'filetype' => $rich_media->filetype, 'size' => preg_match('/^(big|medium|small)$/', $rich_media->size) ? $rich_media->size : 'big', 'orientation' => preg_match('/^(left|right|full|background)$/', $rich_media->orientation) ? $rich_media->orientation : 'full', 'caption' => $rich_media->caption, 'credit' => $rich_media->credit, 'poster' => isset($rich_media->poster) ? $rich_media->poster : '');
            } else {
                $value = trim(strip_tags($doc->saveXml($paragraph), '<a>'));
                if (!empty($value)) {
                    $output['chapters'][$heading]['content'][] = array('filename' => NULL, 'filetype' => 'text', 'size' => null, 'orientation' => null, 'caption' => $value);
                }
                // $output['chapters'][$heading]['content'][] = strip_tags($paragraph->nodeValue, 'a');
            }
        }
        // if the string isn't empty
    }
    //Now write this to a file.
    file_put_contents('/Library/WebServer/Documents/portland/app/data/' . $file_name . '.json', json_encode($output)) or die('Could not open file for writing.');
    echo date("Y-m-d H:i:s") . " successful import. \r\n";
}
开发者ID:bangordailynews,项目名称:multimediaprojects,代码行数:58,代码来源:importer.php

示例4: 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);
 }
开发者ID:blendinteractive,项目名称:ez-sitemap-bundle,代码行数:41,代码来源:GenerateCommand.php

示例5: show

 function show()
 {
     $channel_id = intval($this->input['channel_id']);
     if (!$channel_id) {
         $this->errorOutput('未传入频道id');
     }
     $sql = "SELECT id, start_time, toff, theme FROM " . DB_PREFIX . "program ";
     $sql .= " WHERE channel_id = " . $channel_id . " AND start_time>=" . TIMENOW;
     $sql .= " ORDER BY start_time ASC LIMIT 1";
     $program_info = $this->db->query_first($sql);
     $sql = "SELECT name, logo_info, stream_id FROM " . DB_PREFIX . "channel ";
     $sql .= " WHERE id = " . $channel_id;
     $channel_info = $this->db->query_first($sql);
     $logo_url = '';
     if ($channel_info['logo_info']) {
         $logo_info = @unserialize($channel_info['logo_info']);
         $logo_url = hg_material_link($logo_info['host'], $logo_info['dir'], $logo_info['filepath'], $logo_info['filename']);
     }
     header('Content-Type: text/xml; charset=UTF-8');
     $dom = new DOMDocument('1.0', 'utf-8');
     $channel = $dom->createElement('channel');
     $channel->setAttribute('name', $channel_info['name']);
     $channel->setAttribute('url', $logo_url);
     $channel->setAttribute('current', $channel_info['stream_id']);
     $logos = $dom->createElement('logos');
     $item = $dom->createElement('item');
     $item->setAttribute('url', $channel_info['logo']);
     $logos->appendChild($item);
     $channel->appendChild($logos);
     $dom->appendChild($channel);
     echo $dom->saveXml();
 }
开发者ID:h3len,项目名称:Project,代码行数:32,代码来源:channel_xml.php

示例6: testSerialize

 /**
  * @todo Implement testSerialize().
  */
 public function testSerialize()
 {
     $dom = new DOMDocument();
     $dom->appendChild($dom->createElement('xml'));
     $this->object->serialize('test', $dom->documentElement);
     self::assertXmlStringEqualsXmlString('<xml>test</xml>', $dom->saveXml());
 }
开发者ID:kandy,项目名称:system,代码行数:10,代码来源:NativeTest.php

示例7: 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;
 }
开发者ID:romainneutron,项目名称:Phraseanet,代码行数:38,代码来源:downloadmailfail.php

示例8: wpr_gtrns

function wpr_gtrns($text, $from, $to) {
	$url = "http://translate.google.com/translate_t";
	$ref = "http://translate.google.com/translate_t";
	$text=urlencode($text);
	if($to=="tw"||$to=="cn") {
		$to="zh-".strtoupper($to);
	}
	if($to=="nor") {$to=="no";}
	$postdata="hl=en&ie=UTF8&text=".$text."&langpair=".$from."%7C".$to;
	$page = wpr_gettr($url, $postdata, $ref);
	if(!empty($page["error"]["reason"])) {
		return $page;
	}
	
		$dom = new DOMDocument();
		@$dom->loadHTML($page);
		$xpath = new DOMXPath($dom);
		$paras = $xpath->query("//span[@id='result_box']"); // additional span? //span[@id='result_box']/span
		
		$para = $paras->item(0);
		$string = $dom->saveXml($para);	
		//$string = utf8_decode($string);
	if ($string!="") {
		return stripslashes(strip_tags($string));
	} else {
		return "";
	}
}
开发者ID:erudith,项目名称:fullpower,代码行数:28,代码来源:translation.php

示例9: show

 function show()
 {
     $channel_id = $this->input['channel_id'];
     if (!$channel_id) {
         $this->errorOutput('该频道不存在或者已被删除');
     }
     $dates = $this->input['dates'];
     if (!$dates) {
         $this->errorOutput('这一天不存在节目');
     }
     $sql = "select * from " . DB_PREFIX . "program where channel_id=" . $channel_id . " AND dates='" . $dates . "' ORDER BY start_time ASC ";
     $q = $this->db->query($sql);
     header('Content-Type: text/xml; charset=UTF-8');
     $dom = new DOMDocument('1.0', 'utf-8');
     $program = $dom->createElement('program');
     while ($row = $this->db->fetch_array($q)) {
         $item = $dom->createElement('item');
         $item->setAttribute('name', urldecode($row['theme']));
         $item->setAttribute('startTime', $row['start_time'] * 1000);
         $item->setAttribute('duration', $row['toff'] * 1000);
         $program->appendChild($item);
     }
     $dom->appendChild($program);
     echo $dom->saveXml();
 }
开发者ID:h3len,项目名称:Project,代码行数:25,代码来源:program_xml.php

示例10: format_xml_string

function format_xml_string($xml)
{
    if ($dom = new DOMDocument()) {
        $dom->preserveWhiteSpace = FALSE;
        $dom->formatOutput = TRUE;
        $dom->loadXML('<root><foo><bar>baz</bar></foo></root>');
        return (string) $dom->saveXml();
    } else {
        $xml = preg_replace('/(>)(<)(\\/*)/', "\$1\n\$2\$3", $xml);
        $token = strtok($xml, "\n");
        $result = '';
        $pad = 0;
        $matches = array();
        while ($token !== FALSE) {
            if (preg_match('/.+<\\/\\w[^>]*>$/', $token, $matches)) {
                $indent = 0;
            } elseif (preg_match('/^<\\/\\w/', $token, $matches)) {
                $pad--;
                $indent = 0;
            } elseif (preg_match('/^<\\w[^>]*[^\\/]>.*$/', $token, $matches)) {
                $indent = 1;
            } else {
                $indent = 0;
            }
            $line = str_pad($token, strlen($token) + $pad, ' ', STR_PAD_LEFT);
            $result .= $line . "\n";
            $token = strtok("\n");
            $pad += $indent;
        }
        return (string) $result;
        // reference
        // http://www.daveperrett.com/articles/2007/04/05/format-xml-with-php/
    }
}
开发者ID:tfont,项目名称:skyfire,代码行数:34,代码来源:format_xml_string.func.php

示例11: sanitizeXml

 /**
  * Normalizes a given xml string to be compareable.
  *
  * @param string $xml
  * @return string
  */
 protected function sanitizeXml($xml)
 {
     $dom = new \DOMDocument();
     $dom->loadXml($xml);
     //$dom->normalizeDocument();
     return $dom->saveXml();
 }
开发者ID:lapistano,项目名称:wsunit,代码行数:13,代码来源:SerializerArrayTest.php

示例12: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $buildNumber = $input->getArgument('buildnumber');
     if (empty($buildNumber)) {
         throw new \InvalidArgumentException('Missing build number.');
     }
     $screenshotsRegex = $input->getArgument('screenshotsRegex');
     $plugin = $input->getOption('plugin');
     $httpUser = $input->getOption('http-user');
     $httpPassword = $input->getOption('http-password');
     $urlBase = $this->getUrlBase($plugin, $buildNumber);
     $diffviewer = $this->getDiffviewerContent($output, $urlBase, $httpUser, $httpPassword);
     $dom = new \DOMDocument();
     $dom->loadHTML($diffviewer);
     foreach ($dom->getElementsByTagName("tr") as $row) {
         $columns = $row->getElementsByTagName("td");
         $processedColumn = $columns->item(3);
         $file = null;
         if ($processedColumn && preg_match("/href=\".*\\/(.*)\"/", $dom->saveXml($processedColumn), $matches)) {
             $file = $matches[1];
         }
         if ($file !== null && preg_match("/" . $screenshotsRegex . "/", $file)) {
             $this->downloadProcessedScreenshot($output, $urlBase, $file, $plugin, $httpUser, $httpPassword);
         }
     }
     $this->displayGitInstructions($output, $plugin);
 }
开发者ID:ahdinosaur,项目名称:analytics.dinosaur.is,代码行数:27,代码来源:SyncScreenshots.php

示例13: beautify

function beautify($xml)
{
    $dom = new DOMDocument();
    $dom->preserveWhiteSpace = false;
    $dom->loadXML($xml);
    $dom->formatOutput = true;
    return $dom->saveXml();
}
开发者ID:ziegenberg,项目名称:email-autodiscover,代码行数:8,代码来源:autodiscover.xml.php

示例14: moduleAccessDeniedAction

 /**
  * Returns small XML error message if access to module has been denied.
  */
 public function moduleAccessDeniedAction()
 {
     $response = $this->getResponse();
     $response->setHttpResponseCode(401);
     $doc = new DOMDocument();
     $doc->appendChild($doc->createElement('error', 'Unauthorized: Access to module not allowed.'));
     $this->getResponse()->setBody($doc->saveXml());
 }
开发者ID:belapp,项目名称:opus4-application,代码行数:11,代码来源:IndexController.php

示例15: testSerialize

 /**
  * @todo Implement testSerialize().
  */
 public function testSerialize()
 {
     // Remove the following lines when you implement this test.
     $dom = new DOMDocument();
     $dom->appendChild($dom->createElement('xml'));
     $this->object->serialize(array('a' => 'b'), $dom->documentElement);
     self::assertXmlStringEqualsXmlString('<xml><a>b</a></xml>', $dom->saveXml());
 }
开发者ID:kandy,项目名称:system,代码行数:11,代码来源:DomTest.php


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