/** * normalizes $input into a CertissimXMLElement object with children * use cases: * createChild(XMLElement) --> won't do anything * createChild(simpleXMLElement) * createChild("<element a='1' b='2'>valeur</element>") * createChild("element","valeur", array('a'=>1, 'b'=>2)) * * @param mixed $input * @param string $value * @param string $attributes * @return XMLElement objet normalized */ private function createChild($input, $value = null, $attributes = array()) { if (is_string($input) && !SceauTools::isXMLstring($input)) { $str = "<{$input}"; foreach ($attributes as $name => $val) { $str .= " {$name}='{$val}'"; } $str .= '>'; if (!is_null($value)) { $str .= $value; } $str .= "</{$input}>"; $input = new SimpleXMLElement($str); } if (is_string($input) || SceauTools::isSimpleXMLElement($input)) { $input = new SceauXMLElement($input); } if (!SceauTools::isXMLElement($input)) { $msg = "Le type du paramètre entré n'est pas pris en compte par la classe SceauXMLElement : " . get_class($input); SceauTools::insertLog(get_class($this) . " - createChild()", $msg); throw new Exception($msg); } return $input; }