name = $name; $this->value = $value; $this->attributes = []; $this->children = []; } public function addChild(XmlNode $child) { $this->children[] = $child; return $this; } public function createChild($name, $value = null) { $child = new XmlNode($name, $value); $this->addChild($child); return $child; } public function addAttribute($name, $value) { $this->attributes[$name] = $value; return $this; } public function getXml() { $xml = "<".$this->name; foreach ($this->attributes as $name => $value) { $xml .= " ".$name."=\"".$value."\""; } if(count($this->children) == 0 && $this->value === null) { $xml .= "/>"; return $xml; } $xml .= ">"; if ($this->value !== null) { $xml .= $this->value; } foreach ($this->children as $child) { $xml .= $child->getXml(); } $xml .= "name.">"; return $xml; } } class XmlWriter { public $nodes; public $indent; public function __construct() { $this->indent = 0; } /** * Ajoute un noeud à la sortie * @param XmlNode $node * @return $this */ public function addNode(XmlNode $node) { $this->nodes[] = $node; } public function createNode($name, $value = null) { $node = new XmlNode($name, $value); $this->addNode($node); return $node; } public function export() { $xml = ""; foreach ($this->nodes as $node) { $xml .= $node->getXml(); } return $xml; } }