/** * Save FB2 file * @param string $path */ public function save($path = '') { if ($this->fictionBook instanceof FictionBook) { self::$FB2DOM = new \DOMDocument("1.0", "UTF-8"); self::$FB2DOM->preserveWhiteSpace = FALSE; self::$FB2DOM->formatOutput = TRUE; $this->fictionBook->buildXML(); self::$FB2DOM->schemaValidate("./XSD/FB2.2/FictionBook.xsd"); //$domDoc->schemaValidate("./XSD/FB2.0/FictionBook2.xsd"); self::$FB2DOM->save($path); echo self::$FB2DOM->saveXML(); } }
function loadSX() { $xml = simplexml_load_file($this->_xml); $newDoc = new DOMDocument(); $products = $newDoc->createElement("Allitems"); foreach ($xml as $product) { $domDoc = new DOMDocument(); $domDoc->loadXML($product->asXML()); $x = $domDoc->documentElement; if (!$domDoc->schemaValidate($this->_xsd)) { $errors = libxml_get_errors(); foreach ($errors as $error) { //print libxml_display_error($error); } libxml_clear_errors(); } else { print "validation successful\n"; $item = $newDoc->createElement("Item"); $i = 1; foreach ($x->childNodes as $ele) { if (!$ele instanceof DOMElement) { continue; } $nodeData = $newDoc->createElement(trim($ele->nodeName), $ele->nodeValue); $item->appendChild($nodeData); } $products->appendChild($item); $newDoc->appendChild($products); $newDoc->formatOutput = true; print $newDoc->saveXML(); } } print_r($newDoc->saveXML()); }
/** * @desc This method process a uploaded file with the upload method form and * validate this uploaded file front to a xsd file in the upload folder */ public function do_upload() { $ud = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR; $config['upload_path'] = $ud . 'temp' . DIRECTORY_SEPARATOR; $config['allowed_types'] = 'xml'; $config['max_size'] = 1024 * 1024; $this->load->library('upload', $config); if (!$this->upload->do_upload()) { $error = array('error' => $this->upload->display_errors()); $this->load->view('upload', $error); } else { $data = array('upload_data' => $this->upload->data()); $document = new DOMDocument(); $document->loadXML(file_get_contents($data['upload_data']['full_path'])); if ($document->schemaValidate(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'books.xsd')) { $data['message'] = 'File successfully loaded'; unlink($ud . "books.xml"); rename($data['upload_data']['full_path'], $ud . "books.xml"); } else { $xsdUrl = base_url('books.xsd'); $data['error'] = "<span style='color: red'>Xml file not valid, please verify and try again, if need see xsd file must be downloaded from <a href='{$xsdUrl}' target='_blank'>{$xsdUrl}</a></span><br />"; } $this->load->view('upload', $data); } }
public function validate() { $document = new \DOMDocument(); $document->loadXML($this->asXML()); $filename = 'path/to/schema.xsd'; return $document->schemaValidate($filename); }
/** * Check a given XML file against the DRV rules * * @param string $pathToFile full path to the XML file * @return bool if there were any errors during processing */ private function is_valid_drv_file($pathToFile) { $hasErrors = false; // Enable user error handling libxml_use_internal_errors(true); $xml = new \DOMDocument(); $xml->load($pathToFile); $pathToSchema = realpath($this->get('kernel')->getRootDir() . '/Resources/drv_import/meldungen_2010.xsd'); if (!file_exists($pathToSchema)) { $message = 'Konnte DRV-Schema auf Server nicht finden!'; $this->addFlash('error', $message); $this->get('logger')->warning($message . ' Gesuchter Pfad: ' . $pathToSchema); $hasErrors = true; } if (!$hasErrors && !$xml->schemaValidate($pathToSchema)) { if (self::DRV_DEBUG) { print '<b>DOMDocument::schemaValidate() generated Errors!</b>' . "\n"; $errors = libxml_get_errors(); libxml_clear_errors(); foreach ($errors as $error) { print '<<<<<<<<<<<<<<<<<<<<<<<<<' . "\n"; print $this->libxml_display_error($error); print_r($error); print '>>>>>>>>>>>>>>>>>>>>>>>>>' . "\n"; } } else { $this->addFlash('error', 'Nur XML-Export-Dateien vom DRV sind erlaubt!'); $hasErrors = true; } } return $hasErrors; }
function testAddFunctionMultiple() { $server = new Zend_Soap_AutoDiscover(); $server->addFunction('Zend_Soap_AutoDiscover_TestFunc'); $server->addFunction('Zend_Soap_AutoDiscover_TestFunc2'); $server->addFunction('Zend_Soap_AutoDiscover_TestFunc3'); $server->addFunction('Zend_Soap_AutoDiscover_TestFunc4'); $server->addFunction('Zend_Soap_AutoDiscover_TestFunc5'); $server->addFunction('Zend_Soap_AutoDiscover_TestFunc6'); $server->addFunction('Zend_Soap_AutoDiscover_TestFunc7'); $server->addFunction('Zend_Soap_AutoDiscover_TestFunc9'); $dom = new DOMDocument(); ob_start(); $server->handle(); $dom->loadXML(ob_get_contents()); $dom->save(dirname(__FILE__) . '/addfunction2.wsdl'); ob_end_clean(); $parts = explode('.', basename($_SERVER['SCRIPT_NAME'])); $name = $parts[0]; $wsdl = '<?xml version="1.0"?> <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://' . $_SERVER['PHP_SELF'] . '" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" name="' . $name . '" targetNamespace="http://' . $_SERVER['PHP_SELF'] . '"><portType name="' . $name . 'Port"><operation name="Zend_Soap_AutoDiscover_TestFunc"><input message="tns:Zend_Soap_AutoDiscover_TestFuncRequest"/><output message="tns:Zend_Soap_AutoDiscover_TestFuncResponse"/></operation><operation name="Zend_Soap_AutoDiscover_TestFunc2"><input message="tns:Zend_Soap_AutoDiscover_TestFunc2Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc2Response"/></operation><operation name="Zend_Soap_AutoDiscover_TestFunc3"><input message="tns:Zend_Soap_AutoDiscover_TestFunc3Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc3Response"/></operation><operation name="Zend_Soap_AutoDiscover_TestFunc4"><input message="tns:Zend_Soap_AutoDiscover_TestFunc4Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc4Response"/></operation><operation name="Zend_Soap_AutoDiscover_TestFunc5"><input message="tns:Zend_Soap_AutoDiscover_TestFunc5Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc5Response"/></operation><operation name="Zend_Soap_AutoDiscover_TestFunc6"><input message="tns:Zend_Soap_AutoDiscover_TestFunc6Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc6Response"/></operation><operation name="Zend_Soap_AutoDiscover_TestFunc7"><input message="tns:Zend_Soap_AutoDiscover_TestFunc7Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc7Response"/></operation><operation name="Zend_Soap_AutoDiscover_TestFunc9"><input message="tns:Zend_Soap_AutoDiscover_TestFunc9Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc9Response"/></operation></portType><binding name="' . $name . 'Binding" type="tns:' . $name . 'Port"><soap:operation soapAction="http://' . $_SERVER['PHP_SELF'] . '#Zend_Soap_AutoDiscover_TestFunc9"/><soap:operation soapAction="http://' . $_SERVER['PHP_SELF'] . '#Zend_Soap_AutoDiscover_TestFunc7"/><soap:operation soapAction="http://' . $_SERVER['PHP_SELF'] . '#Zend_Soap_AutoDiscover_TestFunc6"/><soap:operation soapAction="http://' . $_SERVER['PHP_SELF'] . '#Zend_Soap_AutoDiscover_TestFunc5"/><soap:operation soapAction="http://' . $_SERVER['PHP_SELF'] . '#Zend_Soap_AutoDiscover_TestFunc4"/><soap:operation soapAction="http://' . $_SERVER['PHP_SELF'] . '#Zend_Soap_AutoDiscover_TestFunc3"/><soap:operation soapAction="http://' . $_SERVER['PHP_SELF'] . '#Zend_Soap_AutoDiscover_TestFunc2"/><soap:operation soapAction="http://' . $_SERVER['PHP_SELF'] . '#Zend_Soap_AutoDiscover_TestFunc"/><soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/><operation name="Zend_Soap_AutoDiscover_TestFunc"><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation name="Zend_Soap_AutoDiscover_TestFunc2"><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation name="Zend_Soap_AutoDiscover_TestFunc3"><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation name="Zend_Soap_AutoDiscover_TestFunc4"><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation name="Zend_Soap_AutoDiscover_TestFunc5"><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation name="Zend_Soap_AutoDiscover_TestFunc6"><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation name="Zend_Soap_AutoDiscover_TestFunc7"><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation name="Zend_Soap_AutoDiscover_TestFunc9"><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation></binding><service name="' . $name . 'Service"><port name="' . $name . 'Port" binding="tns:' . $name . 'Binding"><soap:address location="http://' . $_SERVER['PHP_SELF'] . '"/></port></service><message name="Zend_Soap_AutoDiscover_TestFuncRequest"><part name="who" type="xsd:string"/></message><message name="Zend_Soap_AutoDiscover_TestFuncResponse"><part name="Zend_Soap_AutoDiscover_TestFuncReturn" type="xsd:string"/></message><message name="Zend_Soap_AutoDiscover_TestFunc2Request"/><message name="Zend_Soap_AutoDiscover_TestFunc3Request"/><message name="Zend_Soap_AutoDiscover_TestFunc3Response"><part name="Zend_Soap_AutoDiscover_TestFunc3Return" type="xsd:boolean"/></message><message name="Zend_Soap_AutoDiscover_TestFunc4Request"/><message name="Zend_Soap_AutoDiscover_TestFunc4Response"><part name="Zend_Soap_AutoDiscover_TestFunc4Return" type="xsd:boolean"/></message><message name="Zend_Soap_AutoDiscover_TestFunc5Request"/><message name="Zend_Soap_AutoDiscover_TestFunc5Response"><part name="Zend_Soap_AutoDiscover_TestFunc5Return" type="xsd:int"/></message><message name="Zend_Soap_AutoDiscover_TestFunc6Request"/><message name="Zend_Soap_AutoDiscover_TestFunc6Response"><part name="Zend_Soap_AutoDiscover_TestFunc6Return" type="xsd:string"/></message><message name="Zend_Soap_AutoDiscover_TestFunc7Request"/><message name="Zend_Soap_AutoDiscover_TestFunc7Response"><part name="Zend_Soap_AutoDiscover_TestFunc7Return" type="soap-enc:Array"/></message><message name="Zend_Soap_AutoDiscover_TestFunc9Request"><part name="foo" type="xsd:string"/><part name="bar" type="xsd:string"/></message><message name="Zend_Soap_AutoDiscover_TestFunc9Response"><part name="Zend_Soap_AutoDiscover_TestFunc9Return" type="xsd:string"/></message></definitions> '; $this->assertEquals($wsdl, $dom->saveXML(), "Bad WSDL generated"); $this->assertTrue($dom->schemaValidate(dirname(__FILE__) . '/schemas/wsdl.xsd'), "WSDL Did not validate"); }
/** * @param string $xml * @param string $schema * * @return XsdError[] */ private function validate($xml, $schema) { $result = []; libxml_clear_errors(); $doc = new \DOMDocument(); set_error_handler(function ($errno, $errstr, $errfile, $errline, array $errcontext) use(&$result) { $error = new XsdError(XsdError::FATAL, $errno, $errstr, 0, 0); $result[] = $error; }); $schemaFile = __DIR__ . '/../../../../../xsd/' . $schema; if (!is_file($schemaFile)) { throw new LightSamlXmlException('Invalid schema specified'); } $ok = @$doc->loadXML($xml); if (!$ok) { restore_error_handler(); return [new XsdError(XsdError::FATAL, 0, 'Invalid XML', 0, 0)]; } @$doc->schemaValidate($schemaFile); /** @var \LibXMLError[] $errors */ $errors = libxml_get_errors(); foreach ($errors as $error) { $err = XsdError::fromLibXMLError($error); $result[] = $err; } restore_error_handler(); return $result; }
function __construct($XSD_SCHEMA) { $this->EDIFACT = array("INTERCHANGE_HEADER" => array("SYNTAX_IDENTIFIER" => array("SYNTAX_IDENTIFIER" => "TEST", "SYNTAX_VERSION_NUMBER" => "TEST", "SERVICE_CODE_LIST_DIRECTORY_VERSION_NUMBER" => "TEST", "CHARACTER_ENCODING" => "TEST"), "INTERCHANGE_SENDER" => array("INTERCHANGE_SENDER_IDENTIFICATION" => "TEST", "IDENTIFICATION_CODE_QUALIFIER" => "TEST", "INTERCHANGE_SENDER_INTERNAL_IDENTIFICATION" => "TEST", "INTERCHANGE_SENDER_INTERNAL_SUB_IDENTIFICATION" => "TEST"), "INTERCHANGE_RECEIPENT" => array("INTERCHANGE_RECEIPENT_IDENTIFICATION" => "TEST", "IDENTIFICATION_CODE_QUALIFIER" => "TEST", "INTERCHANGE_RECEIPENT_INTERNAL_IDENTIFICATION" => "TEST", "INTERCHANGE_RECEIPENT_INTERNAL_SUB_IDENTIFICATION" => "TEST"), "SYNTAX_IDENTIFIER" => array("SYNTAX_IDENTIFIER" => "TEST", "SYNTAX_VERSION_NUMBER" => "TEST", "SERVICE_CODE_LIST_DIRECTORY_VERSION_NUMBER" => "TEST", "CHARACTER_ENCODING" => "TEST"), "DATE_AND_TIME_OF_PREPARATION" => array("DATE" => "TEST", "TIME" => "TEST"), "RECEIPENT_S_REFERENCE_PASSWORD_DETAILS" => array("RECEIPENT_REFERENCE_PASSWORD" => "TEST", "RECEIPENT_REFERENCE_PASSWORD_QUALIFIER" => "TEST"), "APPLICATION_REFERENCE" => "TEST", "PROCESSING_PRIORITY_CODE" => "TEST", "ACKNOWLEDGE_AGREEMENT_IDENTIFIER" => "TEST", "INTERCHANGE_AGREEMENT_IDENTIFIER" => "TEST", "TEST_INDICATOR" => "TEST")); $XML = new DOMDocument(); $XML->loadXML($this->ARRAY_TO_XML($this->EDIFACT)); var_dump($XML->schemaValidate($XSD_SCHEMA)); }
/** * @param string $xmlMappingFile * @dataProvider dataValidSchema */ public function testValidateXmlSchema($xmlMappingFile) { $xsdSchemaFile = __DIR__ . "/../../../../../doctrine-mapping.xsd"; $dom = new \DOMDocument('UTF-8'); $dom->load($xmlMappingFile); $this->assertTrue($dom->schemaValidate($xsdSchemaFile)); }
public static function load($xmlfile) { if (is_file($xmlfile)) { $dom = new \DOMDocument(); libxml_use_internal_errors(true); $dom->load($xmlfile); if ($dom->schemaValidate(__DIR__ . "/../Resources/xsd/star.xsd")) { $root = $dom->documentElement; // Preliminary path modifications foreach ($root->getElementsByTagName("include") as $include) { $include->nodeValue = FileUtils::resolveRelativePath(FileUtils::getFileParent($xmlfile), $include->nodeValue); } // Reading attributes $actions = array(); foreach (XMLUtils::getChildrenByName($root, "action") as $child) { $actions[] = AbstractAction::parse($child); } $subsites = array(); foreach (XMLUtils::getChildrenByName($root, "subsite") as $child) { $subsites[] = Subsite::parse($child); } $targets = array(); foreach (XMLUtils::getChildrenByName($root, "target") as $child) { $targets[] = Target::parse($child); } return new Site($subsites, $targets, $actions); } else { //$errors = libxml_get_errors(); throw new \Exception("Document validation failed for '" . $xmlfile . "'"); } } else { throw new \Exception("Not a file '" . $xmlfile . "'"); } }
/** * Validate the xml file * * @return bool */ public function validate() { // Check if a valid xml is given. if (null === $this->xml) { $this->addError('No valid xml given.'); return false; } // Check if the validation file exists $dataDir = Mage::getConfig()->getModuleDir('etc', 'Itabs_Debit') . DS . 'data' . DS; $filePath = $dataDir . $this->getSchema(); if (!file_exists($filePath)) { $this->addError('XSD for validation does not exist.'); return false; } libxml_use_internal_errors(true); $dom = new DOMDocument(); // Check if the xml document is well formed $result = $dom->loadXML($this->getXml()); if ($result === false) { $this->addError('Document is not well formed.'); return false; } // Validate the xml against the schema if (!$dom->schemaValidate($filePath)) { $documentErrors = "Document is not valid:\n"; $errors = libxml_get_errors(); foreach ($errors as $error) { /* @var $error LibXMLError */ $documentErrors .= "---\n" . sprintf("file: %s, line: %s, column: %s, level: %s, code: %s\nError: %s", basename($error->file), $error->line, $error->column, $error->level, $error->code, $error->message); } $this->addError($documentErrors); return false; } return true; }
public function validate() { $source = $this->toXML(); preg_match_all('/schemaLocation=(".+"|\'.+\')/U', $source, $matches); $locations = array(); if (isset($matches[1])) { foreach ($matches[1] as $match) { $location = substr($match, 1, -1); if (strpos($location, " ") === false) { $locations[] = $location; } else { $location = preg_replace("/ {2,}/", " ", $location); $_tmp = explode(" ", $location); for ($i = 1, $c = count($_tmp); $i < $c; $i += 2) { $locations[] = $_tmp[$i]; } } } } $handler = new Sabel_Xml_Validate_ErrorHandler(); set_error_handler(array($handler, "setError")); foreach ($locations as $location) { $this->document->schemaValidate($location); } restore_error_handler(); return $handler; }
function validaXML($sXML, $xsdFile) { libxml_use_internal_errors(true); $dom = new DOMDocument(); $xml = $dom->loadXML($sXML); $erromsg = ''; if (!$dom->schemaValidate($xsdFile)) { $aIntErrors = libxml_get_errors(); $flagOK = FALSE; foreach ($aIntErrors as $intError) { switch ($intError->level) { case LIBXML_ERR_WARNING: $erromsg .= " Atenção {$intError->code}: "; break; case LIBXML_ERR_ERROR: $erromsg .= " Erro {$intError->code}: "; break; case LIBXML_ERR_FATAL: $erromsg .= " Erro fatal {$intError->code}: "; break; } $erromsg .= $intError->message . ';'; } } else { $flagOK = TRUE; $this->errorStatus = FALSE; $this->errorMsg = ''; } if (!$flagOK) { $this->errorStatus = TRUE; $this->errorMsg = $erromsg; } return $flagOK; }
function assertSchemaValidate($xml) { $xsd = __DIR__ . "/../../cache/FATCA XML Schema v1.1/FatcaXML_v1.1.xsd"; $doc = new \DOMDocument(); $xmlDom = $doc->loadXML($xml); $this->assertTrue($doc->schemaValidate($xsd)); }
/** * @dataProvider dataValidateSchemaFiles * @param string $file */ public function testValidateSchema($file) { $found = false; $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->load($file); $dbalElements = $dom->getElementsByTagNameNS("http://symfony.com/schema/dic/doctrine", "config"); if ($dbalElements->length) { $dbalDom = new \DOMDocument('1.0', 'UTF-8'); $dbalNode = $dbalDom->importNode($dbalElements->item(0)); $dbalDom->appendChild($dbalNode); $ret = $dbalDom->schemaValidate(__DIR__ . "/../../Resources/config/schema/doctrine-1.0.xsd"); $this->assertTrue($ret, "DoctrineBundle Dependency Injection XMLSchema did not validate this XML instance."); $found = true; } $ormElements = $dom->getElementsByTagNameNS("http://symfony.com/schema/dic/doctrine", "config"); if ($ormElements->length) { $ormDom = new \DOMDocument('1.0', 'UTF-8'); $ormNode = $ormDom->importNode($ormElements->item(0)); $ormDom->appendChild($ormNode); $ret = $ormDom->schemaValidate(__DIR__ . "/../../Resources/config/schema/doctrine-1.0.xsd"); $this->assertTrue($ret, "DoctrineBundle Dependency Injection XMLSchema did not validate this XML instance."); $found = true; } $this->assertTrue($found, "Neither <doctrine:orm> nor <doctrine:dbal> elements found in given XML. Are namespaces configured correctly?"); }
/** * {@inheritdoc} */ public function loadMetadataFromFile(\ReflectionClass $class, $path) { $classMetadata = new ClassMetadata($class->getName()); $use = libxml_use_internal_errors(true); $dom = new \DOMDocument('1.0'); $dom->load($path); if (!$dom->schemaValidate(__DIR__ . '/../../../schema/mapping.xsd')) { $message = array_reduce(libxml_get_errors(), function ($foo, $error) { return $error->message; }); throw new \InvalidArgumentException(sprintf('Could not validate XML mapping at "%s": %s', $path, $message)); } libxml_use_internal_errors($use); $xpath = new \DOMXpath($dom); $xpath->registerNamespace('psict', self::XML_NAMESPACE); foreach ($xpath->query('//psict:class') as $classEl) { $classAttr = $classEl->getAttribute('name'); if ($classAttr !== $class->getName()) { throw new \InvalidArgumentException(sprintf('Expected class name to be "%s" but it is mapped as "%s"', $class->getName(), $classAttr)); } foreach ($xpath->query('./psict:field', $classEl) as $fieldEl) { $shared = $this->extractOptionSet($xpath, $fieldEl, 'shared-options'); $form = $this->extractOptionSet($xpath, $fieldEl, 'form-options'); $view = $this->extractOptionSet($xpath, $fieldEl, 'view-options'); $storage = $this->extractOptionSet($xpath, $fieldEl, 'storage-options'); $propertyMetadata = new PropertyMetadata($class->getName(), $fieldEl->getAttribute('name'), $fieldEl->getAttribute('type'), $fieldEl->getAttribute('role'), $fieldEl->getAttribute('group'), ['shared' => $shared, 'form' => $form, 'view' => $view, 'storage' => $storage]); $classMetadata->addPropertyMetadata($propertyMetadata); } } return $classMetadata; }
public function testBusinessAreaRequestClass() { $address = new Address(); $address->street = "Sv. Mateja"; $address->houseNumber = "19"; $address->zipCode = "10000"; $address->settlement = "Zagreb"; $address->city = "Zagreb"; $addressData = new AddressData(); $addressData->setAddress($address); $businessArea = new BusinessArea(); $businessArea->setAddressData($addressData); $date = Carbon::now()->format("d.m.Y"); $businessArea->setDateOfusage($date); $businessArea->setNoteOfBusinessArea("ODV1"); //$businessArea->setNoteOfClosing("Z"); $businessArea->setOib("32314900695"); $businessArea->setSpecificPurpose("spec namjena"); $businessArea->setWorkingTime("Pon:08-11h Uto:15-17"); $businessAreaRequest = new BusinessAreaRequest($businessArea); $xml = new DOMDocument(); $xml->loadXML($businessAreaRequest->toXML()); $res = $xml->schemaValidate('./src/schema/FiskalizacijaSchema.xsd'); $this->assertTrue($res); }
/** * @inheritdoc */ protected function doLoad($file) { libxml_use_internal_errors(true); $xml = new \DOMDocument(); $xml->load($file); if (!$xml->schemaValidate(__DIR__ . DIRECTORY_SEPARATOR . "XML" . DIRECTORY_SEPARATOR . "configuration.xsd")) { libxml_clear_errors(); throw MigrationException::configurationNotValid('XML configuration did not pass the validation test.'); } $xml = simplexml_load_file($file, "SimpleXMLElement", LIBXML_NOCDATA); $config = []; if (isset($xml->name)) { $config['name'] = (string) $xml->name; } if (isset($xml->table['name'])) { $config['table_name'] = (string) $xml->table['name']; } if (isset($xml->table['column'])) { $config['column_name'] = (string) $xml->table['column']; } if (isset($xml->{'migrations-namespace'})) { $config['migrations_namespace'] = (string) $xml->{'migrations-namespace'}; } if (isset($xml->{'organize-migrations'})) { $config['organize_migrations'] = $xml->{'organize-migrations'}; } if (isset($xml->{'migrations-directory'})) { $config['migrations_directory'] = $this->getDirectoryRelativeToFile($file, (string) $xml->{'migrations-directory'}); } if (isset($xml->migrations->migration)) { $config['migrations'] = $xml->migrations->migration; } $this->setConfiguration($config); }
/** * Validate self contents towards to specified schema * * @param string $schemaFile absolute path to schema file * @param array &$errors * @return bool */ public function validate($schemaFile, &$errors = array()) { libxml_use_internal_errors(true); $result = $this->_dom->schemaValidate($schemaFile); $errors = libxml_get_errors(); libxml_use_internal_errors(false); return $result; }
/** * Evaluates positive match. * * @param string $name * @param mixed $subject * @param array $arguments */ public function positiveMatch($name, $subject, array $arguments) { $dom = new \DOMDocument(); $dom->loadXML($subject->getDisplay()); if (!$dom->schemaValidate(__DIR__ . '/../../..' . JUNIT_XSD_PATH)) { throw new FailureException(sprintf("Output was not valid JUnit XML")); } }
public function testConvert_XMLValidationCallBack_ValidXML() { $valid = $this->gitDown->convert('phpunit.xml', function ($file) { $doc = new \DOMDocument(); $doc->loadXML($file); return $doc->schemaValidate(__DIR__ . '/../samples/phpunit.xsd'); }); $this->assertEquals(true, $valid); }
/** * Test standard generation against XML schema. * * @return void */ public function testGenerate() { $checkstyleReport = new PHP_CodeSniffer_Reports_Xml(); $generated = $this->getFixtureReport($checkstyleReport); $xmlDocument = new DOMDocument(); $xmlDocument->loadXML($generated); $result = $xmlDocument->schemaValidate(dirname(__FILE__) . '/XSD/Xml.xsd'); $this->assertTrue($result); }
public function test2() { $xml = file_get_contents(__DIR__ . "/expected1.xml"); $doc = new \DOMDocument(); $xmlDom = $doc->loadXML($xml); $this->assertTrue($xmlDom, sprintf("Invalid XML: %s", $xml)); $xsd = __DIR__ . "/../../cache/FATCA XML Schema v1.1/FatcaXML_v1.1.xsd"; $this->assertTrue($doc->schemaValidate($xsd)); }
/** * @throws \InvalidArgumentException When xml doesn't validate its xsd schema */ protected function validate(\DOMDocument $dom) { $schema = __DIR__ . '/../../Resources/config/schema/routing/rest_routing-1.0.xsd'; $current = libxml_use_internal_errors(true); if (!$dom->schemaValidate($schema)) { throw new \InvalidArgumentException(implode("\n", $this->getXmlErrors())); } libxml_use_internal_errors($current); }
protected function _validateXml($xml) { $dom = new DOMDocument(); $dom->loadXML($xml); if ($dom->schemaValidate(self::getConfigData('iopn_schema'))) { return true; } return false; }
function xtestToXmlValidateSchemaLive() { // makes sure the schema documents match $expected_xml = '<publisher name="test"><supportedRuleTypes><type>action</type><type>actor</type><type>tag</type><type>to</type><type>regarding</type><type>source</type><type>keyword</type></supportedRuleTypes></publisher>'; $doc = new DOMDocument(); $doc->loadXML($expected_xml); $doc->saveXML(); $doc->schemaValidate('https://api-v21.gnip.com/schema/gnip.xsd'); }
/** * * @param string $xml * @param string $painformat * @return boolean */ public function validate($xml, $painformat = 'pain.001.001.03') { $reader = new \DOMDocument(); $reader->loadXML($xml); if ($reader->schemaValidate(__DIR__ . '/xsd/' . $painformat . '.xsd')) { return true; } return false; }
/** * This function will check/validate the XML file for correctness * Dinamically if will use the best available checker/validator * (expat syntax checker or DOM schema validator */ function validateXMLStructure() { /// Going to perform complete DOM schema validation if (extension_loaded('dom')) { /// Let's capture errors if (function_exists('libxml_use_internal_errors')) { libxml_use_internal_errors(true); // This function is PHP5 only (MDL-8730) } /// Create and load XML file $parser = new DOMDocument(); $parser->load($this->path); /// Only validate if we have a schema if (!empty($this->schema) && file_exists($this->schema)) { $parser->schemaValidate($this->schema); } /// Check for errors $errors = false; if (function_exists('libxml_get_errors')) { $errors = libxml_get_errors(); } /// Prepare errors if (!empty($errors)) { /// Create one structure to store errors $structure = new XMLDBStructure($this->path); /// Add errors to structure $structure->errormsg = 'XML Error: '; foreach ($errors as $error) { $structure->errormsg .= sprintf("%s at line %d. ", trim($error->message, "\n\r\t ."), $error->line); } /// Add structure to file $this->xmldb_structure = $structure; /// Check has failed return false; } } else { if (function_exists('xml_parser_create')) { $parser = xml_parser_create(); if (!xml_parse($parser, file_get_contents($this->path))) { /// Create one structure to store errors $structure = new XMLDBStructure($this->path); /// Add error to structure $structure->errormsg = sprintf("XML Error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)); /// Add structure to file $this->xmldb_structure = $structure; /// Check has failed return false; } /// Free parser resources xml_parser_free($parser); } else { return false; } } return true; }
protected static function SendRequestToGateway($requestString, $testAccount, $gateway) { $serverUrl = 'https://'; if ($testAccount) { $serverUrl .= 'test'; } switch (strtolower($gateway)) { default: case 'worldnet': $serverUrl .= 'payments.worldnettps.com'; break; case 'cashflows': $serverUrl .= 'cashflows.worldnettps.com'; break; case 'payius': $serverUrl .= 'payments.payius.com'; break; case 'pago': $serverUrl .= 'payments.pagotechnology.com'; break; case 'globalone': $serverUrl .= 'payments.globalone.me'; break; } $XMLSchemaFile = $serverUrl . '/merchant/gateway.xsd'; $serverUrl .= '/merchant/xmlpayment'; $requestXML = new DOMDocument("1.0", "utf-8"); $requestXML->formatOutput = true; $requestXML->loadXML($requestString); if (!$requestXML->schemaValidate($XMLSchemaFile)) { die('<b>XML VALIDATION FAILED AGAINST SCHEMA:</b>' . $XMLSchemaFile . libxml_display_errors()); } unset($requestXML); // Initialisation $ch = curl_init(); // Set parameters curl_setopt($ch, CURLOPT_URL, $serverUrl); // Return a variable instead of posting it directly curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-type: application/xml')); // Activate the POST method curl_setopt($ch, CURLOPT_POST, 1); // Request curl_setopt($ch, CURLOPT_POSTFIELDS, $requestString); // execute the connection $result = curl_exec($ch); // Close it curl_close($ch); if ($result != '') { return $result; } else { return '<?xml version="1.0" encoding="UTF-8"?><ERROR><ERRORSTRING>Content is not allowed in prolog.</ERRORSTRING></ERROR>'; } }
private function validateBody($body, $filename, $isIndex = true) { $dom = new \DOMDocument(); @$dom->loadXML($body); $valid = @$dom->schemaValidate($this->getSchema($isIndex)); if (!$valid) { $lastError = libxml_get_last_error(); throw new ValidationFailedException('The given sitemap file (' . $filename . ') did not validate against the sitemap schema (last error: ' . str_replace("\n", '', $lastError->message) . ').'); } }