path = $document->getPath(); $this->document = $document->getDomDocument(); } /** * Return document as string * * Serialize the document to a string an return it. * * @return string */ public function save() { return $this->document->saveXml(); } /** * Validate the input file * * Validate the input file against the specification of the current * document format. * * Returns true, if the validation succeded, and an array with * ezcDocumentValidationError objects otherwise. * * @param string $file * @return mixed */ public function validateFile( $file ) { $oldSetting = libxml_use_internal_errors( true ); libxml_clear_errors(); $document = new DOMDocument(); $document->load( $file ); $document->schemaValidate( $this->options->schema ); // Get all errors $xmlErrors = libxml_get_errors(); $errors = array(); foreach ( $xmlErrors as $error ) { $errors[] = ezcDocumentValidationError::createFromLibXmlError( $error ); } libxml_clear_errors(); libxml_use_internal_errors( $oldSetting ); return ( count( $errors ) ? $errors : true ); } /** * Validate the input string * * Validate the input string against the specification of the current * document format. * * Returns true, if the validation succeded, and an array with * ezcDocumentValidationError objects otherwise. * * @param string $string * @return mixed */ public function validateString( $string ) { $oldSetting = libxml_use_internal_errors( true ); libxml_clear_errors(); $document = new DOMDocument(); $document->loadXml( $string ); $document->schemaValidate( $this->options->schema ); // Get all errors $xmlErrors = libxml_get_errors(); $errors = array(); foreach ( $xmlErrors as $error ) { $errors[] = ezcDocumentValidationError::createFromLibXmlError( $error ); } libxml_clear_errors(); libxml_use_internal_errors( $oldSetting ); return ( count( $errors ) ? $errors : true ); } } ?>