本文整理汇总了PHP中XML::writer方法的典型用法代码示例。如果您正苦于以下问题:PHP XML::writer方法的具体用法?PHP XML::writer怎么用?PHP XML::writer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XML
的用法示例。
在下文中一共展示了XML::writer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCountrySelectBox
/**
* Return a select box with list of countries. Options values are ISO 3166 code of the country
*
* @param string $lang [optional] ISO 639-1 code of output language. Default is null (get the current language)
* @param string $selected [optional] ISO 3166 code of country. Default is null (get the current country)
* @param string $name [optional] Name attribute of the select element. Default is "country"
* @return string <select> element
*/
public static function getCountrySelectBox($lang = null, $selected = null, $name = 'country')
{
if ($lang === null) {
$lang = self::getLang();
}
if (self::$_iso_3166 === null) {
$dir = FW_DIR . DS . 'i18n' . DS . 'iso-3166';
$file = $dir . DS . strtolower($lang) . '.json';
if (!is_file($file)) {
$file = $dir . DS . 'en.json';
}
self::$_iso_3166 = json_decode(file_get_contents($file), true);
}
$html = XML::writer(false);
$html->startElement('select', array('name' => $name));
$html->writeElement('option', '---');
foreach (self::$_iso_3166 as $iso => $label) {
$attr = array();
$attr['value'] = $iso;
if ($selected !== null && strtoupper($selected) === $iso) {
$attr['selected'] = 'selected';
}
$html->writeElement('option', $label, $attr);
}
$html->endElement();
return $html->outputMemory();
}
示例2: _buildRouteCacheFile
/**
* Build a xml cache file with all modules routes rules
*
* @param array $files Array of files paths to parse
*/
private function _buildRouteCacheFile($files)
{
$modules = array();
$lastModified = 0;
$i = 0;
$routes = array();
$ruleslength = array();
$rules = array();
foreach ($files as $file) {
// Get the last modification timestamp to set cache file timestamp
$lastModified = max($lastModified, filemtime($file));
// File is in webapp
if (strncasecmp(WEBAPP_MODULES_DIR, $file, strlen(WEBAPP_MODULES_DIR)) == 0) {
$segments = explode(DS, str_replace(WEBAPP_MODULES_DIR . DS, '', $file));
$inWebapp = true;
} else {
$segments = explode(DS, str_replace(MODULES_DIR . DS, '', $file));
$inWebapp = false;
}
$module = first($segments);
// Module routes file has not already be parsed (when file is overloaded in webapp)
if (!in_array($module, $modules)) {
array_push($modules, $module);
$xml = simplexml_load_file($file);
// Write route rule
foreach ($xml->xpath('//route') as $route) {
$r = array();
$r['rule'] = (string) $route->attributes()->rule;
$r['redirect'] = (string) $route->attributes()->redirect;
if (isset($route->attributes()->id)) {
$r['id'] = (string) $route->attributes()->id;
}
$rules[$i] = $r['rule'];
$ruleslength[$i] = strlen($r['rule']);
$routes[$i] = $r;
$i++;
}
}
}
if (!empty($routes)) {
// Sort routes by length and alphabetic
array_multisort($ruleslength, SORT_DESC, $rules, SORT_DESC, $routes);
// Start a new XML structure
$result = XML::writer();
// Start <routes>
$result->startElement('routes');
foreach ($routes as $route) {
$result->startElement('route', array('rule' => $route['rule'], 'redirect' => $route['redirect']));
if (isset($route['id'])) {
$result->writeAttribute('id', $route['id']);
}
$result->endElement();
}
// </routes>
$result->endElement();
// End document
$result->endDocument();
// Get content and put contents into the cache file
$result->toFile($this->_cacheFile);
// Set cache file modification date
touch($this->_cacheFile, $lastModified);
}
}
示例3: _createFile
/**
* Create and write a new XLIFF file
*
* @param string $string The string to add into <source> node
* @param string $srcLang ISO 639-1 code of the source language
* @param string $origin The name of the original file where is located the given string
*/
private function _createFile($string, $srcLang, $origin)
{
// instantiate a new XML writer
$xml = XML::writer();
// xliff node
$xml->startElement('xliff', array('version' => '1.2', 'xmlns' => 'urn:oasis:names:tc:xliff:document:1.2'));
// file node
$xml->startElement('file', array('source-language' => $srcLang, 'datatype' => 'plaintext', 'original' => $origin));
// body node
$xml->startElement('body');
// trans-unit node
$xml->startElement('trans-unit', array('id' => 1));
// source node
$xml->writeElement('source', $string);
// target node
$xml->writeElement('target', '');
// end trans-unit
$xml->endElement();
// end body
$xml->endElement();
// end file
$xml->endElement();
// end xliff
$xml->endElement();
// end document
$xml->endDocument();
// get content and put contents into the file
$xml->toFile($this->_file);
// instantiate the generated xml file
$this->__construct($this->_file);
}