/** * PHP5 constructor. */ function __construct($source) { # Check if PHP xml isn't compiled # if (!function_exists('xml_parser_create')) { return trigger_error("PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension."); } $parser = xml_parser_create(); $this->parser = $parser; # pass in parser, and a reference to this object # set up handlers # xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, 'feed_start_element', 'feed_end_element'); xml_set_character_data_handler($this->parser, 'feed_cdata'); $status = xml_parse($this->parser, $source); if (!$status) { $errorcode = xml_get_error_code($this->parser); if ($errorcode != XML_ERROR_NONE) { $xml_error = xml_error_string($errorcode); $error_line = xml_get_current_line_number($this->parser); $error_col = xml_get_current_column_number($this->parser); $errormsg = "{$xml_error} at line {$error_line}, column {$error_col}"; $this->error($errormsg); } } xml_parser_free($this->parser); $this->normalize(); }
function parseError( $parser ) { $error = xml_error_string( xml_get_error_code( $parser ) ); $errorLine = xml_get_current_line_number( $parser ); $errorColumn = xml_get_current_column_number( $parser ); return "<b>Error: $error at line $errorLine column $errorColumn</b>"; }
/** * Format resource metadata. * * @param resource $value * * @return string */ protected function formatMetadata($value) { $props = array(); switch (get_resource_type($value)) { case 'stream': $props = stream_get_meta_data($value); break; case 'curl': $props = curl_getinfo($value); break; case 'xml': $props = array('current_byte_index' => xml_get_current_byte_index($value), 'current_column_number' => xml_get_current_column_number($value), 'current_line_number' => xml_get_current_line_number($value), 'error_code' => xml_get_error_code($value)); break; } if (empty($props)) { return '{}'; } $formatted = array(); foreach ($props as $name => $value) { $formatted[] = sprintf('%s: %s', $name, $this->indentValue($this->presentSubValue($value))); } $template = sprintf('{%s%s%%s%s}', PHP_EOL, self::INDENT, PHP_EOL); $glue = sprintf(',%s%s', PHP_EOL, self::INDENT); return sprintf($template, implode($glue, $formatted)); }
function error($msg) { $errf = $this->error_func; $line = xml_get_current_line_number($this->parser); $col = xml_get_current_column_number($this->parser); $errf("{$msg} at line:{$line}, col:{$col}."); }
function get_posts() { if (!$this->fp) { echo "File pointer failed to init."; return false; } $this->parser = xml_parser_create("UTF-8"); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, 'startXML', 'endXML'); xml_set_character_data_handler($this->parser, 'charXML'); xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); $state = 0; while (!feof($this->fp)) { $chunk = fread($this->fp, 8192); // read in 8KB chunks (8192 bytes) if ($state == 0 && trim($chunk) == '') { continue; // scan until it reacheas something (just in case) } elseif ($state == 0 && strpos($chunk, '<?xml') !== false) { // the first chunk, probably includes the header(s) $chunk = preg_replace('#<\\?xml.+?>#i', '', $chunk); // remove the header(s) from the first chunk $state = 1; } if (!xml_parse($this->parser, $chunk, feof($this->fp))) { $this->error(sprintf('XML error at line %d column %d', xml_get_current_line_number($this->parser), xml_get_current_column_number($this->parser)) . ' -' . xml_error_string(xml_get_error_code($this->parser))); } } return $this->posts; }
public function __construct($input, $maxDepth = 20) { if (!is_string($input)) { throw new XmlToArrayException('No valid input.'); } $this->_maxDepth = $maxDepth; $XMLParser = xml_parser_create(); xml_parser_set_option($XMLParser, XML_OPTION_SKIP_WHITE, false); xml_parser_set_option($XMLParser, XML_OPTION_CASE_FOLDING, false); xml_parser_set_option($XMLParser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); xml_set_character_data_handler($XMLParser, array($this, '_contents')); xml_set_default_handler($XMLParser, array($this, '_default')); xml_set_element_handler($XMLParser, array($this, '_start'), array($this, '_end')); xml_set_external_entity_ref_handler($XMLParser, array($this, '_externalEntity')); xml_set_notation_decl_handler($XMLParser, array($this, '_notationDecl')); xml_set_processing_instruction_handler($XMLParser, array($this, '_processingInstruction')); xml_set_unparsed_entity_decl_handler($XMLParser, array($this, '_unparsedEntityDecl')); if (!xml_parse($XMLParser, $input, true)) { $errorCode = xml_get_error_code($XMLParser); $message = sprintf('%s. line: %d, char: %d' . ($this->_tagStack ? ', tag: %s' : ''), xml_error_string($errorCode), xml_get_current_line_number($XMLParser), xml_get_current_column_number($XMLParser) + 1, implode('->', $this->_tagStack)); xml_parser_free($XMLParser); throw new XmlToArrayException($message, $errorCode); } xml_parser_free($XMLParser); }
/** * Create an array structure from an XML string. * * Usage:<br> * <code> * $xml = xmlize($array); * </code> * See the function {@link traverse_xmlize()} for information about the * structure of the array, it's much easier to explain by showing you. * Be aware that the array is somewhat tricky. I use xmlize all the time, * but still need to use {@link traverse_xmlize()} quite often to show me the structure! * * THIS IS A PHP 5 VERSION: * * This modified version basically has a new optional parameter * to specify an OUTPUT encoding. If not specified, it defaults to UTF-8. * I recommend you to read this PHP bug. There you can see how PHP4, PHP5.0.0 * and PHP5.0.2 will handle this. * {@link http://bugs.php.net/bug.php?id=29711} * Ciao, Eloy :-) * * @param string $data The XML source to parse. * @param int $whitespace If set to 1 allows the parser to skip "space" characters in xml document. Default is 1 * @param string $encoding Specify an OUTPUT encoding. If not specified, it defaults to UTF-8. * @param bool $reporterrors if set to true, then a {@link xml_format_exception} * exception will be thrown if the XML is not well-formed. Otherwise errors are ignored. * @return array representation of the parsed XML. */ function xmlize($data, $whitespace = 1, $encoding = 'UTF-8', $reporterrors = false) { $data = trim($data); $vals = array(); $parser = xml_parser_create($encoding); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, $whitespace); xml_parse_into_struct($parser, $data, $vals); // Error handling when the xml file is not well-formed if ($reporterrors) { $errorcode = xml_get_error_code($parser); if ($errorcode) { $exception = new xml_format_exception(xml_error_string($errorcode), xml_get_current_line_number($parser), xml_get_current_column_number($parser)); xml_parser_free($parser); throw $exception; } } xml_parser_free($parser); $i = 0; if (empty($vals)) { // XML file is invalid or empty, return false return false; } $array = array(); $tagname = $vals[$i]['tag']; if (isset($vals[$i]['attributes'])) { $array[$tagname]['@'] = $vals[$i]['attributes']; } else { $array[$tagname]['@'] = array(); } $array[$tagname]["#"] = xml_depth($vals, $i); return $array; }
function MagpieRSS($source) { # if PHP xml isn't compiled in, die # if (!function_exists('xml_parser_create')) { trigger_error("Failed to load PHP's XML Extension. http://www.php.net/manual/en/ref.xml.php"); } $parser = @xml_parser_create(); if (!is_resource($parser)) { trigger_error("Failed to create an instance of PHP's XML parser. http://www.php.net/manual/en/ref.xml.php"); } $this->parser = $parser; # pass in parser, and a reference to this object # set up handlers # xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, 'feed_start_element', 'feed_end_element'); xml_set_character_data_handler($this->parser, 'feed_cdata'); $status = xml_parse($this->parser, $source); if (!$status) { $errorcode = xml_get_error_code($this->parser); if ($errorcode != XML_ERROR_NONE) { $xml_error = xml_error_string($errorcode); $error_line = xml_get_current_line_number($this->parser); $error_col = xml_get_current_column_number($this->parser); $errormsg = "{$xml_error} at line {$error_line}, column {$error_col}"; $this->error($errormsg); } } xml_parser_free($this->parser); $this->normalize(); }
function ParserError($XMLParser) { unset($this->arrFeedItems); unset($this->arrItemData); $this->arrFeedItems['error_code'] = xml_get_error_code($XMLParser); $this->arrFeedItems['line_number'] = xml_get_current_line_number($XMLParser); $this->arrFeedItems['column_number'] = xml_get_current_column_number($XMLParser); }
/** Get the xml error if an an error in the xml file occured during parsing. */ public function get_xml_error() { if ($this->parse_error) { $errCode = xml_get_error_code($this->parser); $thisError = "Error Code [" . $errCode . "] \"<strong style='color:red;'>" . xml_error_string($errCode) . "</strong>\",\n at char " . xml_get_current_column_number($this->parser) . "\n on line " . xml_get_current_line_number($this->parser) . ""; } else { $thisError = $this->parse_error; } return $thisError; }
protected function _parse($data = '') { // Deprecation warning. MLog::add('MSimpleXML::_parse() is deprecated.', MLog::WARNING, 'deprecated'); //Error handling if (!xml_parse($this->_parser, $data)) { $this->_handleError(xml_get_error_code($this->_parser), xml_get_current_line_number($this->_parser), xml_get_current_column_number($this->_parser)); } //Free the parser xml_parser_free($this->_parser); }
public static function castXml($h, array $a, Stub $stub, $isNested) { $a['current_byte_index'] = xml_get_current_byte_index($h); $a['current_column_number'] = xml_get_current_column_number($h); $a['current_line_number'] = xml_get_current_line_number($h); $a['error_code'] = xml_get_error_code($h); if (isset(self::$xmlErrors[$a['error_code']])) { $a['error_code'] = new ConstStub(self::$xmlErrors[$a['error_code']], $a['error_code']); } return $a; }
/** * Factory XML parsing exception. * * @param resource $parser * @throws static */ public static function create($parser) { if (!is_resource($parser) || 'xml' !== get_resource_type($parser)) { $message = 'Argument #1 of "' . __CLASS__ . '::' . __METHOD__ . '" must be a resource returned by "xml_parser_create"'; throw new InvalidArgumentException($message); } $code = xml_get_error_code($parser); $error = xml_error_string($code); $line = xml_get_current_line_number($parser); $column = xml_get_current_column_number($parser); return new static(sprintf('XML parsing error: "%s" at Line %d at column %d', $error, $line, $column), $code); }
public function __construct($message, $parser, \SplFileObject $file = NULL) { $this->code = xml_get_error_code($parser); if (false === $this->code) { throw new \BadMethodCallException('This is not a valid xml_parser resource.'); } parent::__construct($message ?: xml_error_string($this->code), $this->code); $this->file = $file ? $file->getPathname() : '(data stream)'; $this->line = xml_get_current_line_number($parser); $this->err['srcColumn'] = xml_get_current_column_number($parser); $this->err['srcIndex'] = xml_get_current_byte_index($parser); }
function Parse($data) { if (!xml_parse($this->parser, $data)) { $this->data = array(); $this->errorCode = xml_get_error_code($this->parser); $this->errorString = xml_error_string($this->errorCode); $this->currentLine = xml_get_current_line_number($this->parser); $this->currentColumn = xml_get_current_column_number($this->parser); } else { $this->data = $this->data['child']; } xml_parser_free($this->parser); }
function parse() { $parser = $this->parser; xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); // Dont mess with my cAsE sEtTings xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); // Dont bother with empty info if (!xml_parse_into_struct($parser, $this->rawXML, $this->valueArray, $this->keyArray)) { $this->status = 'error: ' . xml_error_string(xml_get_error_code($parser)) . ' at line ' . xml_get_current_line_number($parser) . ' at column ' . xml_get_current_column_number($parser); return false; } xml_parser_free($parser); $this->findDuplicateKeys(); // tmp array used for stacking $stack = array(); $increment = 0; foreach ($this->valueArray as $val) { if ($val['type'] == "open") { //if array key is duplicate then send in increment if (array_key_exists($val['tag'], $this->duplicateKeys)) { array_push($stack, $this->duplicateKeys[$val['tag']]); $this->duplicateKeys[$val['tag']]++; } else { // else send in tag array_push($stack, $val['tag']); } } elseif ($val['type'] == "close") { array_pop($stack); // reset the increment if they tag does not exists in the stack if (array_key_exists($val['tag'], $stack)) { $this->duplicateKeys[$val['tag']] = 0; } } elseif ($val['type'] == "complete") { //if array key is duplicate then send in increment if (array_key_exists($val['tag'], $this->duplicateKeys)) { array_push($stack, $this->duplicateKeys[$val['tag']]); $this->duplicateKeys[$val['tag']]++; } else { // else send in tag array_push($stack, $val['tag']); } $this->setArrayValue($this->output, $stack, $val['value']); array_pop($stack); } $increment++; } $this->status = 'success'; return true; }
/** * Initiates and runs PHP's XML parser */ public function Parse() { //Create the parser resource $this->parser = xml_parser_create(); //Set the handlers xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, 'StartElement', 'EndElement'); xml_set_character_data_handler($this->parser, 'CharacterData'); //Error handling if (!xml_parse($this->parser, $this->xml)) { $this->HandleError(xml_get_error_code($this->parser), xml_get_current_line_number($this->parser), xml_get_current_column_number($this->parser)); } //Free the parser xml_parser_free($this->parser); }
function parse($url) { $values = ""; $encoding = 'UTF-8'; $data = file_get_contents($url); $parser = xml_parser_create($encoding); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); $ok = xml_parse_into_struct($parser, $data, $values); if (!$ok) { $errmsg = sprintf("XML parse error %d '%s' at line %d, column %d (byte index %d)", xml_get_error_code($parser), xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser), xml_get_current_column_number($parser), xml_get_current_byte_index($parser)); } xml_parser_free($parser); return $this->reorganize($values); }
private static function ExtractArrayFromXMLString($data) { $xmlParser = xml_parser_create_ns('UTF-8'); xml_parser_set_option($xmlParser, XML_OPTION_SKIP_WHITE, 1); xml_parser_set_option($xmlParser, XML_OPTION_CASE_FOLDING, 0); $xmlTags = array(); $rc = xml_parse_into_struct($xmlParser, $data, $xmlTags); if ($rc == false) { throw new CDavXMLParsingException(xml_error_string(xml_get_error_code($xmlParser)), xml_get_current_line_number($xmlParser), xml_get_current_column_number($xmlParser)); } xml_parser_free($xmlParser); if (count($xmlTags) == 0) { $xmlTags = null; } return $xmlTags; }
function parse($data) { $this->parser = xml_parser_create('UTF-8'); xml_set_object($this->parser, $this); xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 1); xml_set_element_handler($this->parser, 'tag_open', 'tag_close'); xml_set_character_data_handler($this->parser, 'cdata'); if (!xml_parse($this->parser, $data)) { $this->data = array(); $this->error_code = xml_get_error_code($this->parser); $this->error_string = xml_error_string($this->error_code); $this->current_line = xml_get_current_line_number($this->parser); $this->current_column = xml_get_current_column_number($this->parser); } xml_parser_free($this->parser); return $this->data; }
public function parse($string) { $this->currentNode = null; $xp = $this->createXmlParser(); $success = xml_parse($xp, $this->parseEntities($string), true); if (!$success) { $code = xml_get_error_code($xp); $msg = xml_error_string($code); $line = xml_get_current_line_number($xp); $col = xml_get_current_column_number($xp); xml_parser_free($xp); $xp = null; throw new \Exception("{$msg} (On line {$line}:{$col})", $code); } xml_parser_free($xp); $xp = null; return $this->currentNode; }
function load(&$lines, &$root) { $this->root =& $root; $xml_parser = xml_parser_create($this->charSet); xml_set_object($xml_parser, $this); xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 1); $data = implode("\n", $lines); unset($lines); $vals = array(); $index = array(); if (!xml_parse_into_struct($xml_parser, $data, $vals, $index)) { $this->error("XML error: %s at line %d col %d", array(xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser), xml_get_current_column_number($xml_parser))); return; } xml_parser_free($xml_parser); $xmlTree = $this->xmlGetChildren($vals, $i = 0); $this->parseTree($this->root, $xmlTree); return true; }
/** * @param string $content * * @return array */ public function parse($content) { $this->payload = []; $parser = xml_parser_create(); xml_set_object($parser, $this); xml_set_element_handler($parser, 'startXML', 'endXML'); xml_set_character_data_handler($parser, 'charXML'); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false); $lines = explode("\n", $content); foreach ($lines as $val) { if (trim($val) == '') { continue; } $data = $val . "\n"; if (!xml_parse($parser, $data)) { throw new \RuntimeException(sprintf('XML error at line %d column %d', xml_get_current_line_number($parser), xml_get_current_column_number($parser))); } } return $this->payload; }
function fetch_remote_list($base_url) { global $request; $result = array(); $list_url = $base_url . '?action=list'; printf("Fetching timezone list\n", $list_url); $raw_xml = file_get_contents($list_url); $xml_parser = xml_parser_create_ns('UTF-8'); $xml_tags = array(); xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 1); xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0); $rc = xml_parse_into_struct($xml_parser, $raw_xml, $xml_tags); if ($rc == false) { dbg_error_log('ERROR', 'XML parsing error: %s at line %d, column %d', xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser), xml_get_current_column_number($xml_parser)); $request->PreconditionFailed(400, 'invalid-xml', sprintf('XML parsing error: %s at line %d, column %d', xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser), xml_get_current_column_number($xml_parser))); } xml_parser_free($xml_parser); $position = 0; return BuildXMLTree($xml_tags, $position); }
/** * Validate XML file for syntax errors and basic node presence. * @param string $filePath * @return string */ public function validateFile($filePath) { /* @var $messageHandler C4B_ProductImport_Model_MessageHandler */ $messageHandler = Mage::getSingleton('xmlimport/messageHandler'); $result = self::VALIDATION_RESULT_OK; $nodeCount = 0; $xmlParser = xml_parser_create(); $xmlReader = new XMLReader(); try { if (!($xmlFile = fopen($filePath, 'r'))) { return self::VALIDATION_RESULT_FILE_ERROR; } while ($result == self::VALIDATION_RESULT_OK && ($readData = fread($xmlFile, 4096))) { if (!xml_parse($xmlParser, $readData, feof($xmlFile))) { $messageHandler->addErrorsForFile(basename($filePath), ' ', sprintf('XML Syntax error: %s at line %d, column %d.', xml_error_string(xml_get_error_code($xmlParser)), xml_get_current_line_number($xmlParser), xml_get_current_column_number($xmlParser))); $result = self::VALIDATION_RESULT_FILE_ERROR; } } if ($result == self::VALIDATION_RESULT_OK) { $xmlReader->open($filePath); if (!$xmlReader->next('products')) { $result = self::VALIDATION_RESULT_NO_ROOT_NODE; } else { $nodeCount = $this->_countProductNodes($xmlReader); } } } catch (Exception $e) { $messageHandler->addErrorsForFile(basename($filePath), ' ', $e->getMessage()); } $xmlReader->close(); fclose($xmlFile); xml_parser_free($xmlParser); if ($nodeCount == 0 && $result == self::VALIDATION_RESULT_OK) { $result = self::VALIDATION_RESULT_NO_PRODUCT_NODES; } else { if ($result == self::VALIDATION_RESULT_OK) { $messageHandler->addNotice("File contains {$nodeCount} product nodes"); } } return $result; }
/** * parse xml * * @param string $xmldata XML data. * @param string $schemaName Schema name. * @param string $module Module name. * * @return mixed Associative array of workflow or false. */ public function parse($xmldata, $schemaName, $module) { // parse XML if (!xml_parse($this->parser, $xmldata, true)) { xml_parser_free($this->parser); throw new \Exception(__f('Unable to parse XML workflow (line %1$s, %2$s): %3$s', array(xml_get_current_line_number($this->parser), xml_get_current_column_number($this->parser), xml_error_string($this->parser)))); } // close parser xml_parser_free($this->parser); // check for errors if ($this->workflow['state'] == 'error') { return LogUtil::registerError($this->workflow['errorMessage']); } $this->mapWorkflow(); if (!$this->validate()) { return false; } $this->workflow['workflow']['module'] = $module; $this->workflow['workflow']['id'] = $schemaName; return $this->workflow; }
function parse(&$xmlContent) { $data = ''; $this->parser = xml_parser_create(); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, 'startXML', 'endXML'); xml_set_character_data_handler($this->parser, 'charXML'); xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); $lines = explode("\n", $xmlContent); foreach ($lines as $val) { if (trim($val) == '') { continue; } $data = $val . "\n"; if (!xml_parse($this->parser, $data)) { $this->error(sprintf('XML error at line %d column %d', xml_get_current_line_number($this->parser), xml_get_current_column_number($this->parser))); } } // $this->cleanup($this->data); return $this->data; }
function parse($file) { $this->wxr_version = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = false; $this->authors = $this->posts = $this->term = $this->category = $this->tag = $this->widget = $this->custom_field = $this->options = array(); $xml = xml_parser_create('UTF-8'); xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1); xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0); xml_set_object($xml, $this); xml_set_character_data_handler($xml, 'cdata'); xml_set_element_handler($xml, 'tag_open', 'tag_close'); if (!xml_parse($xml, file_get_contents($file), true)) { $current_line = xml_get_current_line_number($xml); $current_column = xml_get_current_column_number($xml); $error_code = xml_get_error_code($xml); $error_string = xml_error_string($error_code); return new WP_Error('XML_parse_error', 'There was an error when reading this WXR file', array($current_line, $current_column, $error_string)); } xml_parser_free($xml); if (!preg_match('/^\\d+\\.\\d+$/', $this->wxr_version)) { return new WP_Error('WXR_parse_error', __('This does not appear to be a WXR file, missing/invalid WXR version number', 'cws_demo_imp')); } return array('authors' => $this->authors, 'posts' => $this->posts, 'categories' => $this->category, 'tags' => $this->tag, 'widgets' => $this->widget, 'custom_field' => $this->custom_field, 'terms' => $this->term, 'base_url' => $this->base_url, 'options' => $this->options, 'version' => $this->wxr_version); }
/** * Get parsed data * * Parses an XML file and retuns parsed content wrappen into an {@link * AeXml_Node} class instance. * * @throws AeXmlDriverSimpleException #404 if XML Parser functions are not * available * @throws AeXmlDriverSimpleException #500 on XML Parser error * * @return AeXml_Node */ public function parse() { if (!function_exists('xml_parser_create')) { throw new AeXmlDriverSimpleException('PHP XML Parser functions are not available', 404); } $this->_parser = xml_parser_create('UTF-8'); xml_set_object($this->_parser, $this); xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, 0); // *** Set parse handlers xml_set_element_handler($this->_parser, 'startElement', 'endElement'); xml_set_character_data_handler($this->_parser, 'characterData'); if (!xml_parse($this->_parser, $this->getSource())) { $code = xml_get_error_code($this->_parser); $text = xml_error_string($code); if ($code == 9) { $text .= ' (Line ' . xml_get_current_line_number($this->_parser) . ', character ' . xml_get_current_column_number($this->_parser) . ')'; } throw new AeXmlDriverSimpleException($text, 500); } $return = $this->_result; $this->_result = null; return $return; }
function parse() { // Creates the object tree from XML code $success = true; $error = array(); $this->parser = xml_parser_create($this->encoding); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, "startElement", "endElement"); xml_set_character_data_handler($this->parser, "characterData"); xml_set_default_handler($this->parser, "defaultHandler"); if (!xml_parse($this->parser, $this->xml)) { // Error while parsing document $success = false; $error['err_code'] = $err_code = xml_get_error_code($this->parser); $error['err_string'] = xml_error_string($err_code); $error['err_line'] = xml_get_current_line_number($this->parser); $error['err_col'] = xml_get_current_column_number($this->parser); $error['err_byte'] = xml_get_current_byte_index($this->parser); //print "<p><b>Error Code:</b> $err_code<br>$err_string<br><b>Line:</b> $err_line<br><b>Column: $err_col</p>"; } xml_parser_free($this->parser); return $success === true ? true : $error; }