function xmlEscape($value) { $escapedValue = XMLNode::xmlentities($value, ENT_NOQUOTES); if ($value !== $escapedValue) { return "<![CDATA[{$value}]]>"; } return $value; }
/** * @param $output file handle to write to, or true for stdout, or null if XML to be returned as string * @return string */ function &toXml($output = null) { $nullVar = null; $out = ''; if ($this->parent === null) { // This is the root node. Output information about the document. $out .= "<?xml version=\"" . $this->getAttribute('version') . "\" encoding=\"UTF-8\"?>\n"; if ($this->getAttribute('type') != '') { if ($this->getAttribute('url') != '') { $out .= "<!DOCTYPE " . $this->getAttribute('type') . " PUBLIC \"" . $this->getAttribute('dtd') . "\" \"" . $this->getAttribute('url') . "\">"; } else { $out .= "<!DOCTYPE " . $this->getAttribute('type') . " SYSTEM \"" . $this->getAttribute('dtd') . "\">"; } } } if ($this->name !== null) { $out .= '<' . $this->name; foreach ($this->attributes as $name => $value) { $value = XMLNode::xmlentities($value); $out .= " {$name}=\"{$value}\""; } $out .= '>'; } $out .= XMLNode::xmlentities($this->value, ENT_NOQUOTES); foreach ($this->children as $child) { if ($output !== null) { if ($output === true) { echo $out; } else { fwrite($output, $out); } $out = ''; } $out .= $child->toXml($output); } if ($this->name !== null) { $out .= '</' . $this->name . '>'; } if ($output !== null) { if ($output === true) { echo $out; } else { fwrite($output, $out); } return $nullVar; } return $out; }
/** * Escape XML entities. * @param $string string */ function _escapeXmlEntities($string) { return XMLNode::xmlentities($string); }