标签:
注意:在实际开发中,注意createElement()、createAttribute()、createTextNode()、appendchild()等方法的具体使用。
// root根节点的属性数组配置
$rootArray = [
‘caption‘ => ‘会员账户信息‘,
‘animation‘ => ‘1‘,
‘xAxisName‘ => ‘项目名称‘,
‘yAxisName‘ => ‘单位(元)‘,
‘numberSuffix‘ => ‘元‘,
‘decimals‘ => ‘2‘,
‘baseFont‘ => ‘微软雅黑‘,
‘baseFontSize‘ => ‘12‘,
‘decimalPrecision‘ => ‘0‘,
‘formatNumberScale‘ => ‘0‘,
];
// set节点属性数组配置
$setArray = [
[
‘label‘ => ‘会员充值总额‘,
‘value‘ => $payTotal,
‘color‘=>‘AFD8F8‘,
],
[
‘label‘ => ‘会员冻结资金‘,
‘value‘ => $frozenMoney,
‘color‘=>‘F6BD0F‘,
],
[
‘label‘ => ‘会员可用资金‘,
‘value‘ => $availMoney,
‘color‘=>‘8BBA00‘,
],
[
‘label‘ => ‘订单交易额‘,
‘value‘ => $orderMoney,
‘color‘=>‘FF8E46‘,
],
];
// 创建一个XML文档并设置XML版本和编码
$dom = new \DOMDocument(‘1.0‘,‘utf-8‘);
// 创建graph根节点
$graph = $dom->createElement(‘chart‘);
$dom->appendchild($graph);
// graph根节点添加相关属性和值
foreach($rootArray as $key=>$value)
{
$title = $dom->createAttribute($key);
$graph->appendChild($title);
$titleValue = $dom->createTextNode($value);
$title->appendChild($titleValue);
}
// 创建set子节点
foreach ($setArray as $data)
{
$item = $dom->createElement(‘set‘);
$graph->appendchild($item);
$this->actionCreateAttribute($dom, $item, $data);
}
$dom->save("member_fund_count.xml"); // 保存为XML文档格式
创建XML的用法
标签:
原文地址:http://www.cnblogs.com/itsharehome/p/4719952.html