本文整理汇总了PHP中SimpleXMLExtended::addChild方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXMLExtended::addChild方法的具体用法?PHP SimpleXMLExtended::addChild怎么用?PHP SimpleXMLExtended::addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXMLExtended
的用法示例。
在下文中一共展示了SimpleXMLExtended::addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bm_save_book
function bm_save_book()
{
# create a backup if necessary
if (isset($_POST['current-slug'])) {
$file = $_POST['current-slug'] . '.xml';
@rename(BMBOOKPATH . $file, BMBACKUPPATH . $file);
}
# empty titles are not allowed
if (empty($_POST['book-title'])) {
$_POST['book-title'] = '[No Title]';
}
# set initial slug and filename
if (!empty($_POST['book-slug'])) {
$slug = bm_create_slug($_POST['book-slug']);
} else {
$slug = bm_create_slug($_POST['book-title']);
}
$file = BMBOOKPATH . "{$slug}.xml";
# do not overwrite other books
if (file_exists($file)) {
$count = 1;
$file = BMBOOKPATH . "{$slug}-{$count}.xml";
while (file_exists($file)) {
$file = BMBOOKPATH . "{$slug}-" . ++$count . '.xml';
}
$slug = basename($file, '.xml');
}
# create undo target if there's a backup available
if (isset($_POST['current-slug'])) {
$backup = $slug . ':' . $_POST['current-slug'];
}
# collect $_POST data
$title = safe_slash_html($_POST['book-title']);
$timestamp = strtotime($_POST['book-date'] . ' ' . $_POST['book-time']);
$date = $timestamp ? date('r', $timestamp) : date('r');
$tags = str_replace(array(' ', ',,'), array('', ','), safe_slash_html($_POST['book-tags']));
$private = isset($_POST['book-private']) ? 'Y' : '';
$content = safe_slash_html($_POST['book-content']);
# create xml object
$xml = new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><item></item>');
$obj = $xml->addChild('title');
$obj->addCData($title);
$obj = $xml->addChild('date');
$obj->addCData($date);
$obj = $xml->addChild('tags');
$obj->addCData($tags);
$obj = $xml->addChild('private');
$obj->addCData($private);
$obj = $xml->addChild('content');
$obj->addCData($content);
# write data to file
if (@XMLsave($xml, $file) && bm_update_cache()) {
bm_display_message(i18n_r('books_manager/SUCCESS_SAVE'), false, @$backup);
} else {
bm_display_message(i18n_r('books_manager/SUCCESS_SAVE'), false, @$backup);
}
}
示例2: _xmlbody
/**
* build the xml structure where the content can be inserted
*
* @return void
*/
private function _xmlbody()
{
$dom = new DOMDocument('1.0', 'UTF-8');
$root = $dom->createElement("tns:phpsysinfo");
$root->setAttribute('xmlns:tns', 'http://phpsysinfo.sourceforge.net/');
$root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$root->setAttribute('xsi:schemaLocation', 'http://phpsysinfo.sourceforge.net/phpsysinfo3.xsd');
$dom->appendChild($root);
$this->_xml = new SimpleXMLExtended(simplexml_import_dom($dom), $this->_sysinfo->getEncoding());
$generation = $this->_xml->addChild('Generation');
$generation->addAttribute('version', CommonFunctions::PSI_VERSION);
$generation->addAttribute('timestamp', time());
$options = $this->_xml->addChild('Options');
$options->addAttribute('tempFormat', defined('PSI_TEMP_FORMAT') ? PSI_TEMP_FORMAT : 'c');
$options->addAttribute('byteFormat', defined('PSI_BYTE_FORMAT') ? PSI_BYTE_FORMAT : 'auto_binary');
$options->addAttribute('refresh', defined('PSI_REFRESH') ? PSI_REFRESH : 0);
$options->addAttribute('showPickListTemplate', defined('PSI_SHOW_PICKLIST_TEMPLATE') ? PSI_SHOW_PICKLIST_TEMPLATE ? 'true' : 'false' : 'false');
$options->addAttribute('showPickListLang', defined('PSI_SHOW_PICKLIST_LANG') ? PSI_SHOW_PICKLIST_LANG ? 'true' : 'false' : 'false');
$plug = $this->_xml->addChild('UsedPlugins');
if ($this->_complete_request && count($this->_plugins) > 0) {
foreach ($this->_plugins as $plugin) {
$plug->addChild('Plugin')->addAttribute('name', $plugin);
}
} elseif ($this->_plugin_request && count($this->_plugins) > 0) {
$plug->addChild('Plugin')->addAttribute('name', $this->_plugin);
}
}
示例3: node
/**
* 增加节点值
* @param array $data
* @param SimpleXMLElement $xml
*
* @return void
*/
public static function node($data, SimpleXMLExtended &$xml)
{
foreach ($data as $k => $v) {
if (is_array($v)) {
is_numeric($k) && ($k = substr($xml->getName(), 0, -1));
$subroot = $xml->addChild($k);
self::node($v, $subroot);
} else {
if (is_numeric($v)) {
$xml->addChild($k, $v);
} else {
$xml->addChild($k)->addCData($v);
}
}
}
}
示例4: 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");
}
示例5: _xmlbody
/**
* build the xml structure where the content can be inserted
*
* @return void
*/
private function _xmlbody()
{
$dom = new DOMDocument('1.0', 'UTF-8');
$root = $dom->createElement("tns:phpsysinfo");
$root->setAttribute('xmlns:tns', 'http://phpsysinfo.sourceforge.net/');
$root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$root->setAttribute('xsi:schemaLocation', 'http://phpsysinfo.sourceforge.net/ phpsysinfo3.xsd');
$dom->appendChild($root);
$this->_xml = new SimpleXMLExtended(simplexml_import_dom($dom), $this->_sysinfo->getEncoding());
$generation = $this->_xml->addChild('Generation');
$generation->addAttribute('version', PSI_VERSION_STRING);
$generation->addAttribute('timestamp', time());
$options = $this->_xml->addChild('Options');
$options->addAttribute('tempFormat', defined('PSI_TEMP_FORMAT') ? strtolower(PSI_TEMP_FORMAT) : 'c');
$options->addAttribute('byteFormat', defined('PSI_BYTE_FORMAT') ? strtolower(PSI_BYTE_FORMAT) : 'auto_binary');
if (defined('PSI_REFRESH')) {
if (PSI_REFRESH === false) {
$options->addAttribute('refresh', 0);
} elseif (PSI_REFRESH === true) {
$options->addAttribute('refresh', 1);
} else {
$options->addAttribute('refresh', PSI_REFRESH);
}
} else {
$options->addAttribute('refresh', 60000);
}
if (defined('PSI_FS_USAGE_THRESHOLD')) {
if (PSI_FS_USAGE_THRESHOLD === true) {
$options->addAttribute('threshold', 1);
} elseif (PSI_FS_USAGE_THRESHOLD !== false && PSI_FS_USAGE_THRESHOLD >= 1 && PSI_FS_USAGE_THRESHOLD <= 99) {
$options->addAttribute('threshold', PSI_FS_USAGE_THRESHOLD);
}
} else {
$options->addAttribute('threshold', 90);
}
$options->addAttribute('showPickListTemplate', defined('PSI_SHOW_PICKLIST_TEMPLATE') ? PSI_SHOW_PICKLIST_TEMPLATE ? 'true' : 'false' : 'false');
$options->addAttribute('showPickListLang', defined('PSI_SHOW_PICKLIST_LANG') ? PSI_SHOW_PICKLIST_LANG ? 'true' : 'false' : 'false');
$options->addAttribute('showCPUListExpanded', defined('PSI_SHOW_CPULIST_EXPANDED') ? PSI_SHOW_CPULIST_EXPANDED ? 'true' : 'false' : 'true');
$options->addAttribute('showCPUInfoExpanded', defined('PSI_SHOW_CPUINFO_EXPANDED') ? PSI_SHOW_CPUINFO_EXPANDED ? 'true' : 'false' : 'false');
if (count($this->_plugins) > 0) {
if ($this->_plugin_request) {
$plug = $this->_xml->addChild('UsedPlugins');
$plug->addChild('Plugin')->addAttribute('name', $this->_plugin);
} elseif ($this->_complete_request) {
$plug = $this->_xml->addChild('UsedPlugins');
foreach ($this->_plugins as $plugin) {
$plug->addChild('Plugin')->addAttribute('name', $plugin);
}
} else {
$plug = $this->_xml->addChild('UnusedPlugins');
foreach ($this->_plugins as $plugin) {
$plug->addChild('Plugin')->addAttribute('name', $plugin);
}
}
}
}
示例6: saveXML
/**
* @return bool|mixed
* @author Panagiotis Vagenas <pan.vagenas@gmail.com>
* @since 150213
*/
protected function saveXML()
{
$dir = dirname($this->fileLocation);
if (!file_exists($dir)) {
mkdir($dir, 0755, true);
}
if ($this->simpleXML && !empty($this->fileLocation) && (is_writable($this->fileLocation) || is_writable($dir))) {
$this->simpleXML->addChild($this->createdAtName, date('Y-m-d H:i'));
return $this->simpleXML->asXML($this->fileLocation);
// TODO Will this create the dir path?
}
return false;
}
示例7: toXml
/**
* Function for converting to an XML document.
* Pass in a multi dimensional array or object and this recrusively loops through and builds up an XML document.
*
* @param array $data
* @param string $rootNodeName - what you want the root node to be - defaultsto data.
* @param SimpleXMLElement $xml - should only be used recursively
* @return string XML
*/
public static function toXml($data, $rootNodeName = 'root', $xml = null, $encoding = 'utf-8', $cdata = false)
{
// turn off compatibility mode as simple xml throws a wobbly if you don't.
if (ini_get('zend.ze1_compatibility_mode') == 1) {
ini_set('zend.ze1_compatibility_mode', 0);
}
if ($xml == null) {
$xml = new SimpleXMLExtended("<?xml version='1.0' encoding='" . $encoding . "'?><{$rootNodeName} />");
}
// loop through the data passed in.
foreach ($data as $key => $value) {
// no numeric keys in our xml please!
if (is_numeric($key)) {
// make string key...
//return;
$key = "row";
}
// if there is another array or object found recrusively call this function
if (is_array($value) || is_object($value)) {
$node = $xml->addChild($key);
// recrusive call.
self::toXml($value, $rootNodeName, $node, $encoding, $cdata);
} else {
// add single node.
$value = is_bool($value) ? $value ? 'true' : 'false' : $value;
$value = htmlspecialchars($value);
if ($cdata === true) {
$node = $xml->addChild($key);
$node->addCData($value);
} else {
$xml->addChild($key, $value);
}
}
}
// pass back as string. or simple xml object if you want!
return $xml->asXML();
}
示例8: export_category
public function export_category()
{
$id = $this->session->userdata('admin_id');
$cates = $this->catenews_model->list_all_byuser($id);
$xml = new SimpleXMLExtended("<root></root>");
foreach ($cates as $cate) {
$xml_post = $xml->addChild('category');
$xml_post->addChild('cat_id', $cate->id);
$content = $xml_post->addChild('cat_name');
$content->addCData($cate->catenewsname);
}
$dom = new DOMDocument("1.0");
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml->asXML());
$xml->asXML('export/' . $id . '/category.xml');
}
示例9: bm_cache_to_xml
function bm_cache_to_xml($books)
{
$xml = new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><channel></channel>');
foreach ($books as $book) {
$item = $xml->addChild('item');
$elem = $item->addChild('slug');
$elem->addCData($book['slug']);
$elem = $item->addChild('title');
$elem->addCData($book['title']);
$elem = $item->addChild('date');
$elem->addCData($book['date']);
$elem = $item->addChild('tags');
$elem->addCData($book['tags']);
$elem = $item->addChild('private');
$elem->addCData($book['private']);
}
return @XMLsave($xml, BMBOOKCACHE);
}
示例10: nm_cache_to_xml
function nm_cache_to_xml($posts)
{
$xml = new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><channel></channel>');
foreach ($posts as $post) {
$item = $xml->addChild('item');
$elem = $item->addChild('slug');
$elem->addCData($post['slug']);
$elem = $item->addChild('title');
$elem->addCData($post['title']);
$elem = $item->addChild('date');
$elem->addCData($post['date']);
$elem = $item->addChild('tags');
$elem->addCData($post['tags']);
$elem = $item->addChild('private');
$elem->addCData($post['private']);
$elem = $item->addChild('image');
$elem->addCData($post['image']);
if (!empty($post['author'])) {
$elem = $item->addChild('author');
$elem->addCData($post['author']);
}
}
return @XMLsave($xml, NMPOSTCACHE);
}
示例11: while
if (file_exists($file) && $url != $_POST['existing-url']) {
$count = "1";
$file = GSDATAPAGESPATH . $url . "-" . $count . ".xml";
while (file_exists($file)) {
$count++;
$file = GSDATAPAGESPATH . $url . "-" . $count . ".xml";
}
$url = $url . '-' . $count;
}
// if we are editing an existing page, create a backup
if (file_exists($file)) {
$bakfile = GSBACKUPSPATH . "pages/" . $url . ".bak.xml";
copy($file, $bakfile);
}
$xml = new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><item></item>');
$xml->addChild('pubDate', date('r'));
$note = $xml->addChild('title');
$note->addCData($title);
$note = $xml->addChild('url');
$note->addCData($url);
$note = $xml->addChild('meta');
$note->addCData($metak);
$note = $xml->addChild('metad');
$note->addCData($metad);
$note = $xml->addChild('menu');
$note->addCData($menu);
$note = $xml->addChild('menuOrder');
$note->addCData($menuOrder);
$note = $xml->addChild('menuStatus');
$note->addCData($menuStatus);
$note = $xml->addChild('template');
示例12: nm_save_post
function nm_save_post()
{
# create a backup if necessary
if (isset($_POST['current-slug'])) {
$file = $_POST['current-slug'] . '.xml';
if (dirname(realpath(NMPOSTPATH . $file)) != realpath(NMPOSTPATH)) {
die('');
}
// path traversal
@nm_rename_file(NMPOSTPATH . $file, NMBACKUPPATH . $file);
}
# empty titles are not allowed
if (empty($_POST['post-title']) || trim($_POST['post-title']) == '') {
$_POST['post-title'] = '[No Title]';
}
# set initial slug and filename
if (!empty($_POST['post-slug'])) {
$slug = nm_create_slug($_POST['post-slug']);
} else {
$slug = nm_create_slug($_POST['post-title']);
if ($slug == '') {
$slug = 'post';
}
}
$file = NMPOSTPATH . $slug . '.xml';
# do not overwrite other posts
if (file_exists($file)) {
$count = 1;
$file = NMPOSTPATH . $slug . '-' . $count . '.xml';
while (file_exists($file)) {
$file = NMPOSTPATH . $slug . '-' . ++$count . '.xml';
}
$slug = basename($file, '.xml');
}
# create undo target if there's a backup available
if (isset($_POST['current-slug'])) {
$backup = $slug . ':' . $_POST['current-slug'];
}
# collect $_POST data
$title = safe_slash_html($_POST['post-title']);
$timestamp = strtotime($_POST['post-date'] . ' ' . $_POST['post-time']);
$date = $timestamp ? date('r', $timestamp) : date('r');
$tags = nm_lowercase_tags(trim(preg_replace(array('/\\s+/', '/\\s*,\\s*/', '/,+/'), array(' ', ',', ','), safe_slash_html(trim($_POST['post-tags']))), ','));
$private = isset($_POST['post-private']) ? 'Y' : '';
$image = safe_slash_html($_POST['post-image']);
$content = safe_slash_html($_POST['post-content']);
if (defined('NMSAVEAUTHOR') && NMSAVEAUTHOR) {
if (isset($_POST['author'])) {
$author = safe_slash_html($_POST['author']);
} else {
global $USR;
$author = $USR ? $USR : '';
}
}
# create xml object
$xml = new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><item></item>');
$obj = $xml->addChild('title');
$obj->addCData($title);
$obj = $xml->addChild('date');
$obj->addCData($date);
$obj = $xml->addChild('tags');
$obj->addCData($tags);
$obj = $xml->addChild('private');
$obj->addCData($private);
$obj = $xml->addChild('image');
$obj->addCData($image);
$obj = $xml->addChild('content');
$obj->addCData($content);
if (isset($author)) {
$obj = $xml->addChild('author');
$obj->addCData($author);
}
# write data to file
if (@XMLsave($xml, $file) && nm_update_cache()) {
nm_generate_sitemap();
nm_display_message(i18n_r('news_manager/SUCCESS_SAVE'), false, @$backup);
} else {
nm_display_message(i18n_r('news_manager/ERROR_SAVE'), true);
}
}
示例13: getPWDresetName
$xml->addChild('USR', $USR);
$xml->addChild('PWD', $PASSWD);
$xml->addChild('EMAIL', $EMAIL);
$xml->addChild('HTMLEDITOR', '1');
$xml->addChild('TIMEZONE', $TIMEZONE);
$xml->addChild('LANG', $LANG);
if (!XMLsave($xml, GSUSERSPATH . $file)) {
$kill = i18n_r('CHMOD_ERROR');
}
# create password change trigger file
$flagfile = GSUSERSPATH . getPWDresetName(_id($USR), 'xml');
copy_file(GSUSERSPATH . $file, $flagfile);
# create new GSWEBSITEFILE (website.xml) file
$file = GSWEBSITEFILE;
$xmls = new SimpleXMLExtended('<item></item>');
$note = $xmls->addChild('SITENAME');
$note->addCData($SITENAME);
$note = $xmls->addChild('SITEURL');
$note->addCData($SITEURL);
$xmls->addChild('TEMPLATE', GSINSTALLTEMPLATE);
$xmls->addChild('PRETTYURLS', '');
$xmls->addChild('PERMALINK', '');
$xmls->addChild('SITEUSR', $USR);
$xmls->addChild('SITEABOUT', '');
if (!XMLsave($xmls, GSDATAOTHERPATH . $file)) {
$kill = i18n_r('CHMOD_ERROR');
}
# create default index.xml page
$init = GSDATAPAGESPATH . 'index.xml';
$temp = GSADMININCPATH . 'tmp/tmp-index.xml';
if (!file_exists($init)) {
示例14: delete_in_category
function delete_in_category($file)
{
$data = getXML($file);
$section = $data->parent;
$id = $data->url;
$files = CATEGORIESPATH . '' . $section . '.xml';
if (file_exists($files)) {
$p = 0;
$data = getXML($files);
$array = array();
foreach ($data->children() as $child) {
if (sprintf("%s", $child) != $id) {
$array[$p] = sprintf("%s", $child);
$p++;
}
}
//$array=array_reverse($array);
$xml = new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><item></item>');
$xml->addChild('pubDate', date('r'));
for ($i = 1; $i < $p; $i++) {
$note = $xml->addChild('f' . $i);
$note->addCData($array[$i]);
}
XMLsave($xml, $files);
}
}
示例15: SimpleXMLExtended
$count++;
}
$langs .= '</select><br />';
} else {
$langs = '<b>' . i18n_r('LANGUAGE') . '</b>: <code style="color:red;">' . i18n_r('NONE') . '</code> ';
}
# salt value generation
$api_file = GSDATAOTHERPATH . GSAUTHFILE;
if (!file_exists($api_file)) {
if (getDef('GSUSECUSTOMSALT')) {
$saltval = sha1(GSUSECUSTOMSALT);
} else {
$saltval = generate_salt();
}
$xml = new SimpleXMLExtended('<item></item>');
$note = $xml->addChild('apikey');
$note->addCData($saltval);
if (!XMLsave($xml, $api_file)) {
$kill = i18n_r('CHMOD_ERROR');
}
}
# get salt value
$data = getXML($api_file);
$APIKEY = $data->apikey;
if (empty($APIKEY)) {
$kill = i18n_r('CHMOD_ERROR');
}
$pagetitle = $site_full_name . ' · ' . i18n_r('INSTALLATION');
get_template('header');
?>