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


PHP SimpleXMLExtended::saveXML方法代码示例

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


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

示例1: saveTemplate

 function saveTemplate($data)
 {
     My_Logger::log("in Ajax_TemplateEditorProcessor saveTemplate()");
     $expected = array('filename', 'type', 'time', 'concepts', 'instructions', 'problem');
     $filename = $this->get($data['filename']);
     if (empty($filename)) {
         throw new Exception('Missing Filename');
     }
     My_Logger::log("filename is " . $filename);
     foreach ($expected as $field) {
         $toCheck = $this->get($data[$field]);
         if (empty($toCheck)) {
             //if (empty($this->get($data[$field]))){
             throw new Exception('Missing field: ' . $field);
         }
     }
     //build xml
     $xml = new SimpleXMLExtended('<question/>');
     $xml->addAttribute('type', $this->get($data['type']));
     $xml->addChild('estimated_time', $this->get($data['time']));
     $concepts = $xml->addChild('concepts');
     $concepts->addChild('concept', $this->get($data['concepts']));
     $xml->addChild('difficulty', $this->get($data['difficulty']));
     $xml->addChild('instructions', $this->get($data['instructions']));
     //$xml->problem = null;
     //$xml->problem->addCData($this->get($data['problem']));
     $xml->addCData('problem', $this->get($data['problem']));
     $sc = $xml->addChild('substitutions');
     $subs = $this->get($data['s']);
     if ($subs) {
         foreach ($subs as $sd) {
             if (empty($sd['name']) || empty($sd['value'])) {
                 continue;
             }
             $s = $sc->addCData('substitution', $sd['value']);
             $s->addAttribute('val', $sd['name']);
         }
     }
     $config = new Zend_Config_Ini(APPLICATION_PATH . "/configs/application.ini", APPLICATION_ENV);
     $path = $config->xml->import_path;
     $full_filename = $path . DIRECTORY_SEPARATOR . $filename;
     My_Logger::log("Saving to {$full_filename}");
     $xml->saveXML($full_filename);
     chmod($full_filename, 0666);
     return array('result' => 'success', 'msg' => "File '{$filename}' saved correctly");
 }
开发者ID:sutantyo,项目名称:itec810,代码行数:46,代码来源:TemplateEditorProcessor.php

示例2: saveMenu

 private function saveMenu($post)
 {
     // initialization
     $return = $nodes = $saved = array();
     foreach ($post as $key => $val) {
         if (is_array($val)) {
             $nodes[] = $key;
         }
     }
     // sets up array
     foreach ($post['level'] as $key => $level) {
         foreach ($nodes as $node) {
             $return[$key][$node] = $post[$node][$key];
         }
         // fill empty fields
         if (empty($return[$key]['slug'])) {
             $return[$key]['slug'] = $this->strtoslug($return[$key]['title']);
         }
         // final formatting
         $return[$key]['slug'] = $this->strtoslug($return[$key]['slug']);
         $return[$key]['url'] = $this->transliterate($return[$key]['url']);
         // checks to see slug doesn't already exist
         if (in_array($return[$key]['slug'], $saved)) {
             $return[$key]['slug'] = $return[$key]['slug'] . '-' . rand(0, 100);
         }
         // add to saved array
         $saved[] = $return[$key]['slug'];
     }
     // build xml file
     $xml = new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><channel/>');
     $cdata = array('title', 'url');
     // menu items
     $menu = $xml->addChild('menu');
     foreach ($return as $key => $item) {
         $itemxml = $menu->addChild('item');
         foreach ($item as $field => $val) {
             if (in_array($field, $cdata)) {
                 $itemxml->{$field} = null;
                 $itemxml->{$field}->addCData($val);
             } else {
                 $itemxml->addChild($field, $val);
             }
         }
     }
     // settings
     $settings = $xml->addChild('settings');
     // format the xml file (beautify)
     $dom = new DOMDocument();
     $dom->preserveWhiteSpace = false;
     $dom->loadXML($xml->saveXML());
     $dom->formatOutput = true;
     // save to file
     $post['name'] = $this->strtoslug($post['name']);
     $newfile = GSDATAOTHERPATH . self::FILE . '/' . $post['name'] . '.xml';
     if (isset($post['oldname'])) {
         $oldfile = GSDATAOTHERPATH . self::FILE . '/' . $post['oldname'] . '.xml';
         if (file_exists($oldfile) && !file_exists($newfile)) {
             unlink($oldfile);
         }
     }
     return $dom->save($newfile);
 }
开发者ID:elephantcode,项目名称:elephantcode,代码行数:62,代码来源:class.php

示例3: addCData

<?php

// http://coffeerings.posterous.com/php-simplexml-and-cdata
class SimpleXMLExtended extends SimpleXMLElement
{
    public function addCData($cdata_text)
    {
        $node = dom_import_simplexml($this);
        $no = $node->ownerDocument;
        $node->appendChild($no->createCDATASection($cdata_text));
    }
}
$xmlFile = 'config.xml';
// instead of $xml = new SimpleXMLElement('<site/>');
$xml = new SimpleXMLExtended('<site/>');
$xml->title = NULL;
// VERY IMPORTANT! We need a node where to append
$xml->title->addCData('Site Title');
$xml->title->addAttribute('lang', 'en');
$xml->saveXML($xmlFile);
开发者ID:ahinap,项目名称:wordpress,代码行数:20,代码来源:XmlController.php


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