本文整理汇总了PHP中libxml_get_errors函数的典型用法代码示例。如果您正苦于以下问题:PHP libxml_get_errors函数的具体用法?PHP libxml_get_errors怎么用?PHP libxml_get_errors使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了libxml_get_errors函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: request
/**
* @param string $url
* @param string $method
* @param string $body
*
* @return FhirResponse
*/
public function request($url, $method = 'GET', $body = null)
{
$server_name = null;
foreach ($this->servers as $name => $server) {
if (substr($url, 0, strlen($server['base_url']))) {
$server_name = $name;
break;
}
}
$this->applyServerConfig($server_name ? $this->servers[$server_name] : array());
$this->http_client->setUri($url);
$this->http_client->setMethod($method);
if ($body) {
$this->http_client->setRawData($body, 'application/xml+fhir; charset=utf-8');
}
$response = $this->http_client->request();
$this->http_client->resetParameters();
if ($body = $response->getBody()) {
$use_errors = libxml_use_internal_errors(true);
$value = Yii::app()->fhirMarshal->parseXml($body);
$errors = libxml_get_errors();
libxml_use_internal_errors($use_errors);
if ($errors) {
throw new Exception("Error parsing XML response from {$method} to {$url}: " . print_r($errors, true));
}
} else {
$value = null;
}
return new FhirResponse($response->getStatus(), $value);
}
示例2: read
/**
* Convert string with xml data to php array.
*
* @throws Exception
*
* @param string $string
*
* @return array
*/
public function read($string)
{
libxml_use_internal_errors(true);
libxml_disable_entity_loader(true);
$result = simplexml_load_string($string, null, LIBXML_IMPORT_FLAGS);
if (!$result) {
$errors = libxml_get_errors();
libxml_clear_errors();
foreach ($errors as $error) {
$text = '';
switch ($error->level) {
case LIBXML_ERR_WARNING:
$text .= _s('XML file contains warning %1$s:', $error->code);
break;
case LIBXML_ERR_ERROR:
$text .= _s('XML file contains error %1$s:', $error->code);
break;
case LIBXML_ERR_FATAL:
$text .= _s('XML file contains fatal error %1$s:', $error->code);
break;
}
$text .= trim($error->message) . ' [ Line: ' . $error->line . ' | Column: ' . $error->column . ' ]';
throw new Exception($text);
}
}
$xml = new XMLReader();
$xml->xml($string);
$array = $this->xmlToArray($xml);
$xml->close();
return $array;
}
示例3: load
/**
* Returns array of simple xml objects, where key is a handle name
*
* @return SimpleXmlElement[]
* @throws RuntimeException in case of load error (malformed xml, etc)
*/
public function load()
{
$this->validate();
$original = libxml_use_internal_errors(true);
$simpleXmlElement = simplexml_load_file($this->filePath);
$errors = libxml_get_errors();
libxml_clear_errors();
libxml_use_internal_errors($original);
if ($simpleXmlElement === false) {
$messages = array();
foreach ($errors as $error) {
$messages[] = sprintf('%s, line %s, column %s', trim($error->message), $error->line, $error->column);
}
throw new RuntimeException(sprintf('File "%s" has a malformed xml structure: %s', $this->filePath, PHP_EOL . implode(PHP_EOL, $messages)));
}
$stringXml = array();
// First convert all elements to string,
// as in xml file can be multiple string with the same handle names
foreach ($simpleXmlElement->children() as $key => $element) {
if (!isset($stringXml[$key])) {
$stringXml[$key] = '';
}
foreach ($element->children() as $child) {
$stringXml[$key] .= $child->asXml();
}
}
$result = array();
foreach ($stringXml as $key => $xml) {
$result[$key] = simplexml_load_string(sprintf('<%1$s>%2$s</%1$s>', $key, $xml));
}
return $result;
}
示例4: validate
public function validate($xml,$schema) {
// Enable user error handling
libxml_use_internal_errors(true);
try {
if(empty($xml)) {
throw new Exception("You provided an empty XML string");
}
$doc = DOMDocument::loadXML($xml);
if(!($doc instanceof DOMDocument)){
$this->_errors = libxml_get_errors();
}
if(!@$doc->schemaValidate($schema)){
$this->_errors = libxml_get_errors();
}
} catch (Exception $e) {
$this->_errors = array(0 => array('message'=>$e->getMessage()));
}
// Disable user error handling & Error Cleanup
libxml_use_internal_errors(false);
libxml_clear_errors();
// If there are no errors, assume that it is all OK!
return empty($this->_errors);
}
示例5: runTest
public function runTest()
{
libxml_use_internal_errors(true);
$xml = XMLReader::open(join(DIRECTORY_SEPARATOR, array($this->directory, $this->fileName)));
$xml->setSchema(join(DIRECTORY_SEPARATOR, array($this->directory, $this->xsdFilename)));
$this->logger->trace(__METHOD__);
$this->logger->info(' XML file to test validity is ' . $this->fileName . 'using XSD file ' . $this->xsdFilename);
// You have to parse the XML-file if you want it to be validated
$currentReadCount = 1;
$validationFailed = false;
while ($xml->read() && $validationFailed == false) {
// I want to break as soon as file is shown not to be valid
// We could allow it to collect a few messages, but I think it's best
// to do a manual check once we have discovered the file is not
// correct. Speed is really what we want here!
if ($currentReadCount++ % Constants::XML_PROCESSESING_CHECK_ERROR_COUNT == 0) {
if (count(libxml_get_errors()) > 0) {
$validationFailed = true;
}
}
}
if (count(libxml_get_errors()) == 0) {
$this->testProperty->addTestResult(true);
$this->logger->info(' RESULT Validation of [' . $this->fileName . '] against [' . $this->xsdFilename . '] succeeded');
$this->testProperty->addTestResultDescription('Validation of [' . $this->fileName . '] against [' . $this->xsdFilename . '] succeeded');
$this->testProperty->addTestResultReportDescription('Filen ' . $this->fileName . ' validerer mot filen' . $this->xsdFilename);
} else {
$this->testProperty->addTestResult(false);
$this->logger->error(' RESULT Validation of [' . $this->fileName . '] against [' . $this->xsdFilename . '] failed');
$this->testProperty->addTestResultDescription('Validation of [' . $this->fileName . '] against [' . $this->xsdFilename . '] failed');
$this->testProperty->addTestResultReportDescription('Filen ' . $this->fileName . ' validerer ikke mot filen' . $this->xsdFilename);
}
libxml_clear_errors();
}
示例6: test
/**
* Method to test the value.
*
* @param JXMLElement &$element The JXMLElement object representing the <field /> tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param JRegistry &$input An optional JRegistry object with the entire data set to validate against the entire form.
* @param object &$form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 11.1
* @throws JException on invalid rule.
*/
public function test(&$element, $value, $group = null, &$input = null, &$form = null)
{
if (empty($value)) {
return true;
}
// compatibility workaround: in some environments XML document is
// saved with all "<styles>" element opening tags replaced with
// "<s-tyles>". We allow this replace (as it can be DB security
// concerned: looks like an HTML element <style...) and do not
// report error. Later the original element syntax will be restored
$value = str_replace('<s-tyles>', '<styles>', $value);
// now XML document should be valid
jimport('joomla.utilities.xmlelement');
libxml_use_internal_errors(true);
$xml = simplexml_load_string($value, 'JXMLElement');
if ($xml === false) {
$errors = array(JText::_('MOD_SMARTCDPRO_ERROR_DIGITS_XML_ERROR'));
foreach (libxml_get_errors() as $error) {
$errors[] = 'XML: ' . $error->message;
}
$element['message'] = implode('<br />', $errors);
return false;
}
$field = $xml->getName();
if ($field != 'config') {
$element['message'] = JText::_('MOD_SMARTCDPRO_ERROR_DIGITS_XML_CONFIG_MISSING');
return false;
}
if (!$xml->xpath('//digit[@scope="*"]')) {
$element['message'] = JText::_('MOD_SMARTCDPRO_ERROR_DIGITS_XML_DEFAULT_DIGIT_MISSING');
return false;
}
$element['message'] = '';
return true;
}
示例7: getScheme
/**
* Creates and returns XmlScheme object for addon
*
* @param string $addon_id Addon name
* @param string $path Path to addons
* @return AXmlScheme object
*/
public static function getScheme($addon_id, $path = '')
{
if (empty($path)) {
$path = Registry::get('config.dir.addons');
}
libxml_use_internal_errors(true);
if (!isset(self::$schemas[$addon_id])) {
$_xml = self::readXml($path . $addon_id . '/addon.xml');
if ($_xml !== FALSE) {
$versions = self::getVersionDefinition();
$version = isset($_xml['scheme']) ? (string) $_xml['scheme'] : '1.0';
self::$schemas[$addon_id] = new $versions[$version]($_xml);
} else {
$errors = libxml_get_errors();
$text_errors = array();
foreach ($errors as $error) {
$text_errors[] = self::displayXmlError($error, $_xml);
}
libxml_clear_errors();
if (!empty($text_errors)) {
fn_set_notification('E', __('xml_error'), '<br/>' . implode('<br/>', $text_errors));
}
return false;
}
}
return self::$schemas[$addon_id];
}
示例8: is_valid_drv_file
/**
* 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;
}
示例9: show_internal_errors
function show_internal_errors()
{
foreach (libxml_get_errors() as $error) {
printf("Internal: %s\n", $error->message);
}
libxml_clear_errors();
}
示例10: getParserError
/**
* Fetch error for current parser
*
* @access protected
* @return string the error message
*/
protected function getParserError()
{
$errors = '';
foreach (libxml_get_errors() as $error) {
$return = '';
switch ($error->level) {
case LIBXML_ERR_WARNING:
$return .= "Warning {$error->code}: ";
break;
case LIBXML_ERR_ERROR:
$return .= "Error {$error->code}: ";
break;
case LIBXML_ERR_FATAL:
$return .= "Fatal Error {$error->code}: ";
break;
}
$return .= trim($error->message) . PHP_EOL . " Line: {$error->line}" . PHP_EOL . " Column: {$error->column}";
if ($error->file) {
$return .= PHP_EOL . " File: {$error->file}";
}
#combine with other error messages
$errors .= PHP_EOL . $return;
}
return $errors;
}
示例11: initDomDocument
/**
* Initialize DOM document
*/
public function initDomDocument()
{
if (null === ($document = $this->getDocument())) {
#require_once 'Zend/Dom/Exception.php';
throw new Zend_Dom_Exception('Cannot query; no document registered');
}
libxml_use_internal_errors(true);
$this->_domDocument = new DOMDocument();
switch ($this->getDocumentType()) {
case self::DOC_XML:
$success = $this->_domDocument->loadXML($document);
break;
case self::DOC_HTML:
case self::DOC_XHTML:
default:
$success = $this->_domDocument->loadHTML($document);
break;
}
$errors = libxml_get_errors();
if (!empty($errors)) {
$this->_documentErrors = $errors;
libxml_clear_errors();
}
libxml_use_internal_errors(false);
if (!$success) {
#require_once 'Zend/Dom/Exception.php';
throw new Zend_Dom_Exception(sprintf('Error parsing document (type == %s)', $this->getDocumentType()));
}
return $this;
}
示例12: processXML
protected function processXML($input)
{
try {
if (!isset($input[2])) {
throw new Exception("Invalid Input");
}
libxml_use_internal_errors(true);
// convert the xml into Object
$inputObject = simplexml_load_string($input, "SimpleXMLElement", LIBXML_NOCDATA);
if (!$inputObject) {
// @var Array to store the error messages
$errors = array();
// loop through the errors and store the errors in $errors
foreach (libxml_get_errors() as $e) {
$errors[] = $e->message;
}
// @var String Errors are joined by a newline
$errors = join("\n", $errors);
// throw the error
throw new Exception($errors);
}
// if !$inputObject
foreach ($inputObject as $name => $value) {
$val = strtolower(trim($value)) == '(null)' ? '' : trim($value);
$inputObject->{$name} = $val;
}
return $inputObject;
} catch (Exception $e) {
$this->setError($e->getMessage());
}
}
示例13: importXML
/**
* Import the xml document from the stream into the repository
*
* @param NodeInterface $parentNode as in importXML
* @param NamespaceRegistryInterface $ns as in importXML
* @param string $uri as in importXML
* @param integer $uuidBehavior as in importXML
*
* @see PHPCR\SessionInterface::importXML
*/
public static function importXML(NodeInterface $parentNode, NamespaceRegistryInterface $ns, $uri, $uuidBehavior)
{
$use_errors = libxml_use_internal_errors(true);
libxml_clear_errors();
if (!file_exists($uri)) {
throw new \RuntimeException("File {$uri} does not exist or is not readable");
}
$xml = new FilteredXMLReader();
$xml->open($uri);
if (libxml_get_errors()) {
libxml_use_internal_errors($use_errors);
throw new InvalidSerializedDataException("Invalid xml file {$uri}");
}
$xml->read();
try {
if ('node' == $xml->localName && NamespaceRegistryInterface::NAMESPACE_SV == $xml->namespaceURI) {
// TODO: validate with DTD?
self::importSystemView($parentNode, $ns, $xml, $uuidBehavior);
} else {
self::importDocumentView($parentNode, $ns, $xml, $uuidBehavior);
}
} catch (\Exception $e) {
// restore libxml setting
libxml_use_internal_errors($use_errors);
// and rethrow exception to not hide it
throw $e;
}
libxml_use_internal_errors($use_errors);
}
示例14: convert
/**
* Create a PHP array from the XML file
*
* @param String $xmlFile The XML file or a string containing xml to parse
*
* @return Array
*
* @throws \Propel\Common\Config\Exception\XmlParseException if parse errors occur
*/
public static function convert($xmlToParse)
{
if (!is_string($xmlToParse)) {
throw new InvalidArgumentException("XmlToArrayConverter::convert method expects an xml file to parse, or a string containing valid xml");
}
if (file_exists($xmlToParse)) {
$xmlToParse = file_get_contents($xmlToParse);
}
//Empty xml file returns empty array
if ('' === $xmlToParse) {
return array();
}
if ($xmlToParse[0] !== '<') {
throw new InvalidArgumentException('Invalid xml content');
}
$currentEntityLoader = libxml_disable_entity_loader(true);
$currentInternalErrors = libxml_use_internal_errors(true);
$xml = simplexml_load_string($xmlToParse);
$errors = libxml_get_errors();
libxml_clear_errors();
libxml_use_internal_errors($currentInternalErrors);
libxml_disable_entity_loader($currentEntityLoader);
if (count($errors) > 0) {
throw new XmlParseException($errors);
}
$conf = self::simpleXmlToArray($xml);
return $conf;
}
示例15: getXml
/**
* Convert xml string to SimpleXMLElement
*
* @param string $data String of retrieved data
*
* @return \SimpleXMLElement
* @throws XmlException
*/
public static function getXml($data)
{
if (self::$libXmlLoaded === null) {
self::$libXmlLoaded = extension_loaded('libxml');
}
if (self::$libXmlLoaded) {
libxml_use_internal_errors(true);
}
$simpleXml = simplexml_load_string($data);
if (!$simpleXml) {
if (self::$libXmlLoaded) {
$xmlErrors = libxml_get_errors();
$errors = array();
foreach ($xmlErrors as $error) {
$errors[] = sprintf('Error in file %s on line %d with message : %s', $error->file, $error->line, $error->message);
}
if (count($errors) > 0) {
throw new XmlException(implode("\n", $errors));
}
}
// @codeCoverageIgnore
throw new XmlException('Xml file cound not be loaded.');
}
return $simpleXml;
}