-
<?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() {
-
for ($i =
0,
$j =
count($this->
stack);
$i <
$j;
$i++
) {
-
$this->xml .= $this->indent;
-
}
-
}
-
function push
($element,
$attributes =
array()) {
-
$this->_indent();
-
$this->xml .= '<'.$element;
-
foreach ($attributes as $key => $value) {
-
-
}
-
$this->xml .= ">\n";
-
$this->stack[] = $element;
-
}
-
function element
($element,
$content,
$attributes =
array()) {
-
$this->_indent();
-
$this->xml .= '<'.$element;
-
foreach ($attributes as $key => $value) {
-
-
}
-
$this->
xml .=
'>'.
htmlentities($content).
'</'.
$element.
'>'.
"\n";
-
}
-
function emptyelement
($element,
$attributes =
array()) {
-
$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();
-
-
array('monkey',
'banana',
'Jim'),
-
array('hamster',
'apples',
'Kola'),
-
array('turtle',
'beans',
'Berty'),
-
);
-
-
$xml->push('zoo');
-
foreach ($array as $animal) {
-
$xml->
push('animal',
array('species' =>
$animal[0]));
-
$xml->element('food', $animal[1]);
-
$xml->element('name', $animal[2]);
-
$xml->pop();
-
}
-
$xml->pop();
-
-
-
-
-
?>
-
-
재정의할수 없다는 에러가 뜨네요..
저 당시의 php 버전이 업데이트 되면서 XMLWriter라는 클래스가 만들어진듯..
앞에 _(underbar)를 넣으니까 되는군요.
http://www.php.net/manual/en/book.xmlwriter.php
여기서 php내부 xmlwriter 에 대해서 알수 있습니다 ㅇ_ㅇ