Created
October 9, 2012 12:05
-
-
Save mcfdn/3858391 to your computer and use it in GitHub Desktop.
Validate XML With Zend_Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class App_Validate_Xml extends Zend_Validate_Abstract | |
{ | |
const ERROR_MESSAGE = 'error'; | |
public $xmlError; | |
protected $_messageVariables = array( | |
'xmlError' => 'xmlError' | |
); | |
protected $_messageTemplates = array( | |
self::ERROR_MESSAGE => '%xmlError%' | |
); | |
public function isValid($value) | |
{ | |
libxml_use_internal_errors(true); | |
$dom = new DOMDocument('1.0', 'utf-8'); | |
$dom->loadXML($value); | |
$errors = libxml_get_errors(); | |
if(count($errors) > 0) { | |
foreach($errors as $error) { | |
$this->xmlError = $error->message; | |
$this->_error(self::ERROR_MESSAGE); | |
} | |
return false; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment