• 创建XML的用法


    注意:在实际开发中,注意createElement()、createAttribute()、createTextNode()、appendchild()等方法的具体使用。
     
     1 // root根节点的属性数组配置
     2      $rootArray = [
     3        'caption' => '会员账户信息',
     4        'animation' => '1',
     5        'xAxisName' => '项目名称',
     6        'yAxisName' => '单位(元)',
     7        'numberSuffix' => '元',
     8        'decimals' => '2',
     9        'baseFont' => '微软雅黑',
    10        'baseFontSize' => '12',
    11        'decimalPrecision' => '0',
    12        'formatNumberScale' => '0',
    13      ];
    14      
    15      // set节点属性数组配置
    16      $setArray = [
    17        [
    18         'label' => '会员充值总额',
    19         'value' => $payTotal,
    20         'color'=>'AFD8F8',
    21        ],
    22        [
    23         'label' => '会员冻结资金',
    24         'value' => $frozenMoney,
    25         'color'=>'F6BD0F',
    26        ],
    27        [
    28            'label' => '会员可用资金',
    29            'value' => $availMoney,
    30            'color'=>'8BBA00',
    31        ],
    32        [
    33            'label' => '订单交易额',
    34            'value' => $orderMoney,
    35            'color'=>'FF8E46',
    36        ],        
    37      ];
    38  
    39      // 创建一个XML文档并设置XML版本和编码  
    40      $dom = new DOMDocument('1.0','utf-8');
    41      
    42      // 创建graph根节点
    43      $graph = $dom->createElement('chart');
    44      $dom->appendchild($graph);
    45      
    46      // graph根节点添加相关属性和值
    47      foreach($rootArray as $key=>$value)
    48      {
    49         $title = $dom->createAttribute($key);
    50         $graph->appendChild($title);
    51         $titleValue = $dom->createTextNode($value);
    52         $title->appendChild($titleValue);
    53      }
    54      
    55      // 创建set子节点
    56      foreach ($setArray as $data)
    57      {
    58       $item = $dom->createElement('set');
    59       $graph->appendchild($item);
    60       $this->actionCreateAttribute($dom, $item, $data);
    61      }
    62      
    63      $dom->save("member_fund_count.xml"); // 保存为XML文档格式
  • 相关阅读:
    Deploying a web application to Jetty
    在java语言中执行jruby
    自制chuncked http streaming 流
    ubuntu11.10 rails开发集成vim相关问题
    通过drb集成java和ruby环境
    使用Java Web Start部署JRuby应用
    JRuby使用经验 Ruby language ITeye论坛
    使用Trinidad當Jruby Server.
    高雄 linux usergroup
    Jruby On Rails 的安装及部署实践
  • 原文地址:https://www.cnblogs.com/itsharehome/p/4719952.html
Copyright © 2020-2023  润新知