/** * Returns the xml representation of the element. * * @param bool $verbose If set to true xml comments will be included * @param int $indent The number of spaces for indentation * * @access public * @return string */ public function toXml($verbose = false, $indent = 0) { $str = ''; if ($indent == 0) { // root node $str .= '<?xml version="1.0" encoding="utf-8"?>' . "\n"; } $blank = str_repeat(' ', $indent); $id = strtolower($this->id); $str .= $blank . '<' . $id; if (!empty($this->name)) { $name = EDI_Common_Utils_escapeXmlString($this->name); $str .= ' name="' . utf8_encode($name) . '"'; } $str .= '>'; foreach ($this->children as $child) { if ($child instanceof EDI_Common_Element) { $str .= "\n" . $child->toXml($verbose, $indent + 4); } } $str .= "\n" . $blank . '</' . $id . '>'; return $str; }
/** * Returns the xml representation of the element. * * @param bool $verbose If set to true xml comments will be included * @param int $indent The number of spaces for indentation * * @access public * @return string */ public function toXml($verbose = false, $indent = 0) { $blank = str_repeat(' ', $indent); $cls = get_class($this); $node = strtolower(substr($cls, strrpos($cls, '_') + 1)); $str = ''; if ($verbose && !empty($this->description)) { $desc = EDI_Common_Utils_escapeXmlString($this->description); $str .= $blank . '<!-- ' . utf8_encode($desc) . ' -->' . "\n"; } $id = 'e' . strtolower($this->id); $str .= sprintf('%s<%s name="%s">%s</%s>', $blank, $id, utf8_encode(EDI_Common_Utils_escapeXmlString($this->name)), utf8_encode(EDI_Common_Utils_escapeXmlString($this->getValue())), $id); return $str; }