Guest User

Untitled

a guest
Jan 4th, 2013
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. Array
  2. (
  3. [0] => Array
  4. (
  5. [0] => A
  6. [1] => B
  7. [2] => C
  8. )
  9.  
  10. [1] => Array
  11. (
  12. [0] => 1
  13. [1] => 2
  14. [2] => 3
  15. )
  16.  
  17. [2] => Array
  18. (
  19. [0] => apple
  20. [1] => orange
  21. [2] => banana
  22. )
  23.  
  24. )
  25.  
  26. public function CreateXML($array){
  27.  
  28. foreach ($array as $arr) {
  29. $array2[] = $arr[0];
  30. }
  31.  
  32. $xmlDoc = new DOMDocument();
  33.  
  34. $root = $xmlDoc->appendChild(
  35. $xmlDoc->createElement("rootelement"));
  36.  
  37. $tag = $root->appendChild(
  38. $xmlDoc->createElement("element"));
  39.  
  40. $tag->appendChild(
  41. $xmlDoc->createElement("Letter", $array2[0]));
  42.  
  43. $tag->appendChild(
  44. $xmlDoc->createElement("Number", $array2[1]));
  45.  
  46. $tag->appendChild(
  47. $xmlDoc->createElement("Fruit", $array2[2]));
  48.  
  49. header("Content-Type: text/plain");
  50.  
  51. $xmlDoc->formatOutput = true;
  52.  
  53. echo $xmlDoc->saveXML();
  54. }
  55.  
  56. $newArray = array();
  57. for($i = 0; $i <= count($array[0]); $i++) {
  58. $newArray[] = array($array[0][$i], $array[1][$i], $array[2][$i]);
  59. }
  60.  
  61. // Some XML here
  62.  
  63. foreach($newArray as $row) {
  64. $tag->appendChild(
  65. $xmlDoc->createElement("Letter", $row[0]));
  66.  
  67. $tag->appendChild(
  68. $xmlDoc->createElement("Number", $row[1]));
  69.  
  70. $tag->appendChild(
  71. $xmlDoc->createElement("Fruit", $row[2]));
  72. }
  73.  
  74. // Some more XML and output
Add Comment
Please, Sign In to add comment