本文整理汇总了PHP中Xml::toXml方法的典型用法代码示例。如果您正苦于以下问题:PHP Xml::toXml方法的具体用法?PHP Xml::toXml怎么用?PHP Xml::toXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Xml
的用法示例。
在下文中一共展示了Xml::toXml方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createManifestFile
private function createManifestFile()
{
//------------------------- 创建xml文件 start
//创建xml文件
$xml_data['application'] = ['name' => ['@cdata' => $_POST['name']], 'title' => ['@cdata' => $_POST['title']], 'url' => ['@cdata' => $_POST['url']], 'industry' => ['@cdata' => $_POST['industry']], 'version' => ['@cdata' => $_POST['version']], 'resume' => ['@cdata' => $_POST['resume']], 'author' => ['@cdata' => $_POST['author']], 'position' => ['@cdata' => $_POST['position']], 'thumb' => ['@cdata' => $_POST['thumb']], 'module' => ['@cdata' => $_POST['module']]];
$manifest = Xml::toXml('manifest', $xml_data);
file_put_contents('theme/' . $_POST['name'] . '/manifest.xml', $manifest);
}
示例2: toXml
public static function toXml($data, $parent = 'root')
{
if (!$parent instanceof XmlNode) {
$parent = new XmlElement((string) $parent);
}
switch (true) {
case is_array($data):
case is_object($data):
$parent->setAttribute('type', 'structure');
foreach ($data as $key => $value) {
if (is_int($key)) {
$key = 'element';
}
$node = new XmlElement($key);
$parent->addChild($node);
Xml::toXml($value, $node);
}
break;
case is_bool($data):
$parent->setAttribute('type', 'boolean');
$parent->addChild(new XmlText($data ? 'true' : 'false'));
break;
case is_int($data):
$parent->setAttribute('type', 'integer');
$parent->addChild(new XmlText($data));
break;
case is_string($data):
$parent->setAttribute('type', 'string');
$parent->addChild(new XmlText($data));
break;
case is_float($data):
$parent->setAttribute('type', 'float');
$parent->addChild(new XmlText($data));
break;
case is_double($data):
$parent->setAttribute('type', 'double');
$parent->addChild(new XmlText($data));
break;
case is_null($data):
//break;
//break;
default:
$parent->addChild(new XmlText($data));
break;
}
return $parent;
}
示例3: asXml
protected function asXml($value, $rootName = 'response')
{
$this->setSkipView(true);
$xml = Xml::toXml($value, $rootName);
header('Content-type: text/xml');
echo $xml;
Pimple::instance()->end();
}
示例4: createManifestFile
private function createManifestFile()
{
//------------------------- 创建xml文件 start
//模块动作
$bindings = [];
foreach (['cover', 'rule', 'business', 'home', 'profile', 'member', 'web'] as $type) {
$d = $_POST['bindings'][$type];
foreach ($d['title'] as $k => $v) {
if (!empty($d['title'][$k]) && preg_match('/^\\w+$/i', $d['do'][$k])) {
$bindings[$type]['entry'][] = ['@attributes' => ['title' => $d['title'][$k], 'do' => $d['do'][$k], 'data' => $d['data'][$k], 'directly' => isset($d['directly'][$k]) ? $d['directly'][$k] : TRUE]];
}
}
}
//消息处理
$platformXml = ['subscribes' => [], 'processors' => []];
if (isset($_POST['subscribes'])) {
foreach ($_POST['subscribes'] as $m) {
$platformXml['subscribes']['message'][] = ['@attributes' => ['type' => $m]];
}
}
if (isset($_POST['processors'])) {
foreach ($_POST['processors'] as $m) {
$platformXml['processors']['message'][] = ['@attributes' => ['type' => $m]];
}
}
//创建xml文件
$xml_data = ['@attributes' => ['versionCode' => implode(',', $_POST['versionCode'])], 'application' => ['@attributes' => ['setting' => isset($_POST['setting']) ? TRUE : FALSE], 'name' => ['@cdata' => $_POST['name']], 'title' => ['@cdata' => $_POST['title']], 'url' => ['@cdata' => $_POST['url']], 'version' => ['@cdata' => $_POST['version']], 'industry' => ['@cdata' => $_POST['industry']], 'resume' => ['@cdata' => $_POST['resume']], 'detail' => ['@cdata' => $_POST['detail']], 'author' => ['@cdata' => $_POST['author']], 'industry' => ['@cdata' => $_POST['industry']], 'thumb' => ['@cdata' => $_POST['thumb']], 'cover' => ['@cdata' => $_POST['cover']], 'rule' => ['@attributes' => ['embed' => isset($_POST['rule']) ? $_POST['rule'] : FALSE]]], 'platform' => $platformXml, 'bindings' => $bindings, 'permission' => ['@cdata' => $_POST['permission']], 'install' => ['@cdata' => $_POST['install']], 'uninstall' => ['@cdata' => $_POST['uninstall']], 'upgrade' => ['@cdata' => $_POST['upgrade']]];
$manifest = Xml::toXml('manifest', $xml_data);
file_put_contents('addons/' . $_POST['name'] . '/manifest.xml', $manifest);
}