*/ WBClass::load('WBPAT_Forms_Rule'); /** * patForms Rule WellFormedXML * * Validate XML. Check whether XML is well formed. * * @todo validate against schema * @version 0.1.0 * @package Wombat * @subpackage patForms */ class patForms_Rule_WellFormedXML extends WBPAT_Forms_Rule { /** * default config values * * @var array */ protected $config = array( ); /** * config loader * @var WBConfig_Loader */ private $loader; /** * Initialize validation codes using gettext * * @access protected * @return bool $success Always returns true. * @see $attributeDefaults */ public function loadValidatiorErrorCodes() { $this->validatorErrorCodes = array( 1 => patI18n::dgettext('wombat', 'XML issue: [MESSAGE].'), ); return true; } /** * Validate XML * * Method called by patForms or any patForms_Element to validate the * element or the form. * * Use SimpleXML to check whether XML string is well formed. * * @todo reconsider str_replace for __default and __index * @param patForms_Element $form object * @return bool true on sucess */ public function applyRule($element, $type = PATFORMS_RULE_AFTER_VALIDATION) { libxml_use_internal_errors(true); $value = $element->getValue(); if (simplexml_load_string($value)) { return true; } foreach (libxml_get_errors() as $error) { $info = array( 'message' => trim($error->message) ); $this->addValidationError(1, $info); } return false; } } ?>