반응형
<?php
// Simon Willison, 16th April 2003
// Based on Lars Marius Garshol's Python XMLWriter class
// See http://www.xml.com/pub/a/2003/04/09/py-xml.html
class XmlWriter {
var $xml;
var $indent;
function XmlWriter($indent = ' ') {
$this->indent = $indent;
$this->xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
}
function _indent() {
$this->xml .= $this->indent;
}
}
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
}
$this->xml .= ">\n";
$this->stack[] = $element;
}
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
}
}
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
}
$this->xml .= " />\n";
}
function pop() {
$this->_indent();
$this->xml .= "</$element>\n";
}
function getXml() {
return $this->xml;
}
}
$xml = new XmlWriter();
);
$xml->push('zoo');
foreach ($array as $animal) {
$xml->element('food', $animal[1]);
$xml->element('name', $animal[2]);
$xml->pop();
}
$xml->pop();
?>
반응형