private function QueryPath::parseXMLString in QueryPath 6
Same name and namespace in other branches
- 7.3 QueryPath/QueryPath.php \QueryPath::parseXMLString()
- 7.2 QueryPath/QueryPath.php \QueryPath::parseXMLString()
2 calls to QueryPath::parseXMLString()
- QueryPath::parseXMLFile in QueryPath/
QueryPath.php - QueryPath::__construct in QueryPath/
QueryPath.php
File
- QueryPath/
QueryPath.php, line 1826
Class
Code
private function parseXMLString($string, $flags = NULL) {
$document = new DOMDocument('1.0');
$lead = strtolower(substr($string, 0, 5));
try {
set_error_handler(array(
'QueryPathParseException',
'initializeFromError',
), $this->errTypes);
if (isset($this->options['convert_to_encoding'])) {
$from_enc = isset($this->options['convert_from_encoding']) ? $this->options['convert_from_encoding'] : 'auto';
$to_enc = $this->options['convert_to_encoding'];
if (function_exists('mb_convert_encoding')) {
$string = mb_convert_encoding($string, $to_enc, $from_enc);
}
}
if (!empty($this->options['strip_low_ascii'])) {
$string = filter_var($string, FILTER_UNSAFE_RAW, FILTER_FLAG_ENCODE_LOW);
}
if (empty($this->options['use_parser'])) {
$useParser = '';
}
else {
$useParser = strtolower($this->options['use_parser']);
}
if ($useParser == 'html') {
$document
->loadHTML($string);
}
elseif ($lead == '<?xml' || $useParser == 'xml') {
if ($this->options['replace_entities']) {
$string = QueryPathEntities::replaceAllEntities($string);
}
$document
->loadXML($string, $flags);
}
else {
$document
->loadHTML($string);
}
} catch (Exception $e) {
restore_error_handler();
throw $e;
}
restore_error_handler();
if (empty($document)) {
throw new QueryPathParseException('Unknown parser exception.');
}
return $document;
}