xml简单功能

前端之家收集整理的这篇文章主要介绍了xml简单功能前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. <?PHP
  2. header("Content-Type:text/xml;");
  3.  
  4. $product = array(
  5. array(
  6. 'p_id' => '1','product_type' => '1','sub_category' => '1','name' => '','price' => '','pay_category' => '','rating' => '','icon_url' => '','short_description' => '','app_size' => '','source_type' => '','author_name' => '','packagename' => '','ratings_count' => '','is_star' => '','version_code' => '','hot_rating' => '','special_flag' => '','download_count' => '','version_name' => '','rsa_md5' => '',),array(
  7. 'p_id' => '1',)
  8. );
  9.  
  10.  
  11.  
  12. /**
  13. * 创建XML
  14. * @param string $root
  15. * @param string $sub
  16. * @param array $data
  17. *
  18. * @return xml
  19. */
  20. function createXml( $root,$sub,$data)
  21. {
  22. $dom = new DomDocument('1.0','utf-8');
  23. //创建根节点
  24. $responseTag = $dom->createElement('response');
  25. $dom->appendchild($responseTag);
  26. //创建根节点
  27. $rootTag = $dom->createElement($root);
  28. $responseTag->appendchild($rootTag);
  29. foreach($data as $key=>$val){
  30. //创建子节点
  31. $subTag = $dom->createElement($sub);
  32. if(is_array($val))
  33. {
  34. foreach($val as $k=>$v)
  35. {
  36. //子节点属性
  37. $subTag->setAttribute($k,$v);
  38. }
  39. }
  40. $rootTag->appendchild($subTag);
  41. }
  42. return $dom->saveXML();
  43. }
  44.  
  45. $xml = createXml( 'products','product',$product);
  46.  
  47. echo $xml;
  48.  
  49. /**
  50. *
  51. * @param unknown_type $element
  52. * @param unknown_type $item
  53. */
  54. function createXmlElement($element,$item)
  55. {
  56. }

猜你在找的XML相关文章