/** * Convert Array to XML using comodojo XML class * * Second parameters, if true, will try to prettify xml output * * @param array $data Data to convert * @param string $prettify HTML || TXT (alias true) || false * * @return string XML encoded data */ public final function toXml($data, $prettify = false) { if (!(is_array($data) or is_object($data))) { throw new Exception("Invalid data for XML serialization"); } if (is_object($data)) { $data = $this->objectToArray($data); } $xmlEngine = new XML(); $encoded = $xmlEngine->encode($data); switch ($prettify) { case 'HTML': case 'html': $return = htmlspecialchars($this->xmlToTxt($encoded), ENT_QUOTES); break; case 'TXT': case 'txt': case true: $return = $this->xmlToTxt($encoded); break; default: $return = $encoded; break; } return $return; }
/** * Convert XML to Array using comodojo XML converter * * @param string $data Data to convert * * @return array */ public final function fromXml($data) { if (!is_string($data)) { throw new Exception("Invalid data for XML deserialization"); } $xmlEngine = new XML(); return $xmlEngine->decode($data); }