[ create a new paste ] login | about

Link: http://codepad.org/e0IHyrKz    [ raw code | output | fork ]

PHP, pasted on Dec 23:
<?php

$doc = new DomDocument('1.0');
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;

// create root node
$root = $doc->createElement('root');
$root = $doc->appendChild($root);
$signed_values = array('a' => 'eee', 'b' => 'sd', 'c' => 'df');
// process one row at a time
foreach ($signed_values as $key => $val) {
 // add node for each row
  $occ = $doc->createElement('error');
  $occ = $root->appendChild($occ);
  // add a child node for each field
   foreach ($signed_values as $fieldname => $fieldvalue) {
       $child = $doc->createElement($fieldname);
       $child = $occ->appendChild($child);
       $value = $doc->createTextNode($fieldvalue);
       $value = $child->appendChild($value);
   }
}
// get completed xml document
$xml_string = $doc->saveXML() ;
echo $xml_string;


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xml version="1.0"?>
<root>
  <error>
    <a>eee</a>
    <b>sd</b>
    <c>df</c>
  </error>
  <error>
    <a>eee</a>
    <b>sd</b>
    <c>df</c>
  </error>
  <error>
    <a>eee</a>
    <b>sd</b>
    <c>df</c>
  </error>
</root>


Create a new paste based on this one


Comments: