/** * Tries to build a new Message. * @param string $xmlString to build Message * @return Message if $xmlString was valid, throws Exception otherwise */ public static function createFromXml($xmlString) { $doc = @DOMDocument::loadXML($xmlString); if ($doc == null) { throw new Exception('Unvalid XML string.'); } /* * Validating every message agains a definition in the web is wasting * time. So let's validate against a local schema. if (!$doc->validate()) { throw new Exception('Unvalid XML.'); } */ /* * The validation makes a lot of checks for us. We don't have to look * for '<' and '>' characters. */ if (!$doc->schemaValidate('uBookMessage.xsd')) { throw new Exception('Unvalid uBookMessage.'); } $elem = $doc->documentElement; $from = $elem->getAttribute('from'); $message = new self($from); $message->parseBookList($elem); $message->parseServerList($elem); return $message; }