public function start_process() { if (!$this->path_to_xml_file) { return false; } if (!$this->valid_xml) { return false; } $this->archive_builder = new \eol_schema\ContentArchiveBuilder(array('directory_path' => DOC_ROOT . 'temp/xml_to_archive/')); $this->taxon_ids = array(); $this->media_ids = array(); $this->vernacular_name_ids = array(); $this->reference_ids = array(); $this->agent_ids = array(); $reader = new \XMLReader(); $file = file_get_contents($this->path_to_xml_file); $file = iconv("UTF-8", "UTF-8//IGNORE", $file); $reader->XML($file); $i = 0; while (@$reader->read()) { if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "taxon") { $taxon_xml = $reader->readOuterXML(); $t = simplexml_load_string($taxon_xml, null, LIBXML_NOCDATA); if ($t) { $this->add_taxon_to_archive($t); } $i++; if ($i % 100 == 0) { echo "Parsed taxon {$i} : " . time_elapsed() . "\n"; } // if($i >= 5000) break; } } $this->archive_builder->finalize(); }
/** * @return array */ public function read() { $products = []; while ($this->xml->read()) { if ($this->isProductNode()) { $node = $this->xml->expand(); $products[] = $this->createProduct($node); } } return $products; }
/** * Parses a MySQL dump XML file. * * @param $source * @return Fixture * @throws \TheIconic\Fixtures\Exception\InvalidParserException */ public function parse($source) { $fixtureArray = []; $z = new \XMLReader(); $z->open($source); $doc = new \DOMDocument(); while ($z->read() && $z->name !== 'table_data') { } $tableName = $z->getAttribute('name'); $rowNum = 0; while ($z->read() && $z->name !== 'row') { } while ($z->name === 'row') { $node = simplexml_import_dom($doc->importNode($z->expand(), true)); $totalAttributes = $node->count(); for ($i = 0; $i < $totalAttributes; $i++) { foreach ($node->field[$i]->attributes() as $attribute) { $attribute = (string) $attribute; $value = (string) $node->field[$i]; $namespaces = $node->field[$i]->getNamespaces(true); if (empty($namespaces)) { $fixtureArray[$tableName][$rowNum][$attribute] = $value; } } } $rowNum++; $z->next('row'); } if (empty($fixtureArray)) { throw new InvalidParserException("It was not possible to parse the XML file: {$source}"); } return Fixture::create($fixtureArray); }
/** * Most of the error responses are in same format. */ static function parseNormalError(\XMLReader $xmlReader) { $result = array('Code' => NULL, 'Message' => NULL, 'RequestId' => NULL, 'HostId' => NULL); while ($xmlReader->Read()) { if ($xmlReader->nodeType == \XMLReader::ELEMENT) { switch ($xmlReader->name) { case 'Code': $xmlReader->read(); if ($xmlReader->nodeType == \XMLReader::TEXT) { $result['Code'] = $xmlReader->value; } break; case 'Message': $xmlReader->read(); if ($xmlReader->nodeType == \XMLReader::TEXT) { $result['Message'] = $xmlReader->value; } break; case 'RequestId': $xmlReader->read(); if ($xmlReader->nodeType == \XMLReader::TEXT) { $result['RequestId'] = $xmlReader->value; } break; case 'HostId': $xmlReader->read(); if ($xmlReader->nodeType == \XMLReader::TEXT) { $result['HostId'] = $xmlReader->value; } break; } } } return $result; }
public static function generateAcronymInfo($filename) { static $info; if ($info) { return $info; } $r = new \XMLReader(); if (!$r->open($filename)) { throw new \Exception("Could not open file for accessing acronym information: {$filename}"); } $acronyms = array(); while ($r->read()) { if ($r->nodeType != \XMLReader::ELEMENT) { continue; } if ($r->name == "term") { $r->read(); $k = $r->value; $acronyms[$k] = ""; } else { if ($r->name == "simpara") { $r->read(); $acronyms[$k] = $r->value; } } } $info = $acronyms; return $acronyms; }
/** * filterFeed Reads the XML from the url and filters it based on the provided filter. The results are organized into an array keyed by the unqiue values of the filter. */ function filterFeed() { $reader = new XMLReader(); if (!$reader->open($this->url)) { throw new Exception("Cannot open feed from the provided URL."); } while ($reader->read()) { if ($reader->name == "product") { //get the entire product node. $xml_node = $reader->readOuterXML(); } if ($reader->name == $this->filter) { //read the values for the $this->filter node. $reader->read(); //get string/value from the node we are filtering and explode it by a delimiter. $nodeValues = []; $nodeValues = explode($this->delimiter, $reader->value); if (!empty($nodeValues[$this->index])) { $this->filteredXML[$nodeValues[$this->index]][] = $xml_node; } else { throw new Exception("The index specified does not exist."); } //Go to the next product. $reader->next("product"); } } //if the array has no items then the filtered node does not exist. if (empty($this->filteredXML)) { throw new Exception("{$this->filter} does not exist in the XML."); } }
/** * @throws RuntimeException * @return array of arrays. * array( 'dumpKey' => array( 'match1', 'match2' ) ) */ public function scan() { $openSuccess = $this->reader->open($this->dumpLocation); if (!$openSuccess) { throw new RuntimeException('Failed to open XML: ' . $this->dumpLocation); } $result = array(); foreach ($this->query as $queryKey => $query) { $result[$queryKey] = array(); // Make sure keys are returned even if empty } while ($this->reader->read() && $this->reader->name !== 'page') { } while ($this->reader->name === 'page') { $element = new SimpleXMLElement($this->reader->readOuterXML()); $page = $this->getPageFromElement($element); foreach ($this->query as $queryKey => $query) { $match = $this->matchPage($page, $query); if ($match) { //TODO allow the user to choose what to return $result[$queryKey][] = $page->getTitle()->getTitle(); } } $this->reader->next('page'); } $this->reader->close(); return $result; }
public function rewind() { if ($this->reader->nodeType !== XMLReader::NONE) { throw new BadMethodCallException('Reader can not be rewound'); } $this->index = 0; $this->valid = $this->reader->read(); }
protected function parse() { $depth = 0; $elements = array(); $elements_[$depth] =& $elements; while ($this->xml->read()) { switch ($this->xml->nodeType) { case XMLReader::END_ELEMENT: if ($this->xml->depth - 1 < $depth) { $elements =& $elements_[$depth]; $element =& $elements[sizeof($elements) - 1]; $depth = $this->xml->depth - 1; } break; case XMLReader::ATTRIBUTE: # Read does not go through attributes :( break; case XMLReader::ELEMENT: if (strlen($this->xml->name) == 0) { continue; } if ($this->xml->depth > $depth) { $depth = $this->xml->depth; $elements_[$depth] =& $elements; $elements =& $element['elements']; } $elements[] = array('tag' => $this->xml->name); # Working Element $element =& $elements[sizeof($elements) - 1]; # Attributes if ($this->xml->hasAttributes) { $this->xml->moveToFirstAttribute(); $element['attributes'] = array(); $element['attributes'][$this->xml->name] = $this->xml->value; while ($this->xml->moveToNextAttribute()) { $element['attributes'][$this->xml->name] = $this->xml->value; } } if ($this->xml->isEmptyElement) { if ($this->xml->depth - 1 < $depth) { $elements =& $elements_[$depth]; $element =& $elements[sizeof($elements) - 1]; $depth = $this->xml->depth - 1; } } break; case XMLReader::TEXT: case XMLReader::CDATA: if (!isset($element['value'])) { $element['value'] = $this->xml->value; } else { $element['value'] .= $this->xml->value; } break; } } $this->elements = $elements; }
/** * Process the XML query * @param $xmltext the provided XML */ function processXml($xmltext) { // Load the XML $xml = new XMLReader(); if (!$xml->XML($xmltext)) { echo '<hatter status="no" msg="invalid XML" />'; exit; } // Connect to the database $pdo = pdo_connect(); // Read to the start tag while ($xml->read()) { if ($xml->nodeType == XMLReader::ELEMENT && $xml->name == "hatter") { // We have the hatter tag $magic = $xml->getAttribute("magic"); if ($magic != "NechAtHa6RuzeR8x") { echo '<hatter status="no" msg="magic" />'; exit; } $user = $xml->getAttribute("user"); $password = $xml->getAttribute("pw"); $userid = getUser($pdo, $user, $password); // Read to the hatting tag while ($xml->read()) { if ($xml->nodeType == XMLReader::ELEMENT && $xml->name == "hatting") { $name = $xml->getAttribute("name"); $uri = $xml->getAttribute("uri"); $x = $xml->getAttribute("x"); $y = $xml->getAttribute("y"); $angle = $xml->getAttribute("angle"); $scale = $xml->getAttribute("scale"); $color = $xml->getAttribute("color"); $hat = $xml->getAttribute("hat"); $feather = $xml->getAttribute("feather") == "yes" ? 1 : 0; $nameQ = $pdo->quote($name); $uriQ = $pdo->quote($uri); // Checks if (!is_numeric($x) || !is_numeric($y) || !is_numeric($angle) || !is_numeric($scale) || !is_numeric($color) || !is_numeric($hat)) { echo '<hatter status="no" msg="invalid" />'; exit; } $query = <<<QUERY REPLACE INTO hatting(name, userid, uri, type, x, y, rotation, scale, color, feather) VALUES({$nameQ}, '{$userid}', {$uriQ}, {$hat}, {$x}, {$y}, {$angle}, {$scale}, {$color}, {$feather}) QUERY; if (!$pdo->query($query)) { echo '<hatter status="no" msg="insertfail">' . $query . '</hatter>'; exit; } echo '<hatter status="yes"/>'; exit; } } } } echo '<hatter save="no" msg="invalid XML" />'; }
/** * @return void */ public function rewind() { $this->reader->open($this->file, 'utf-8', defined('LIBXML_COMPACT') ? constant('LIBXML_COMPACT') : 0); while ($this->reader->read()) { if ($this->valid()) { break; } } }
protected function parseInfo(\XMLReader $xml, InfosAbstract $object) { // we don't read the name attribute for the module name as in previous jelix version, it has always to be the directory name if ($object->type == 'application') { $object->name = (string) $xml->getAttribute('name'); } $object->createDate = (string) $xml->getAttribute('createdate'); $locale = array('label' => $this->locale, 'description' => $this->locale); while ($xml->read()) { if (\XMLReader::END_ELEMENT == $xml->nodeType && 'info' == $xml->name) { break; } if ($xml->nodeType == \XMLReader::ELEMENT) { $property = $xml->name; if ('label' == $property || 'description' == $property) { if ($xml->getAttribute('lang') == $locale[$property] || $locale[$property] == '') { $xml->read(); $object->{$property} = $xml->value; if ($locale[$property] == '') { // let's mark we readed the element corresponding to the locale $locale[$property] = '__readed__'; } } } elseif ('author' == $property || 'creator' == $property || 'contributor' == $property) { $person = array(); while ($xml->moveToNextAttribute()) { $attrName = $xml->name; $person[$attrName] = $xml->value; } array_push($object->authors, $person); } elseif ('licence' == $property) { // we support licence and license, but store always as license while ($xml->moveToNextAttribute()) { $attrProperty = 'license' . ucfirst($xml->name); $object->{$attrProperty} = $xml->value; } $xml->read(); $object->license = $xml->value; } else { // <version> <license> <copyright> <homepageURL> <updateURL> // read attributes 'date', 'stability' etc ... and store them into versionDate, versionStability while ($xml->moveToNextAttribute()) { $attrProperty = $property . ucfirst($xml->name); $object->{$attrProperty} = $xml->value; } $xml->read(); if ($property == 'version') { $object->{$property} = $this->fixVersion($xml->value); } else { $object->{$property} = $xml->value; } } } } return $object; }
function main() { var_dump(stream_wrapper_register('strstream', 'StringWrapper')); $r = new XMLReader(); $r->open("strstream://"); var_dump($r->read()); var_dump($r->readOuterXML()); var_dump($r->readInnerXML()); var_dump($r->read()); var_dump($r->readOuterXML()); var_dump($r->readInnerXML()); }
/** * {@inheritdoc} */ public function rewind() { $this->position = 0; $this->reader = new XMLReader(); $this->reader->open($this->file); $this->reader->read(); $this->reader->next(); $this->reader->read(); $this->reader->next(); $this->reader->next(); while ($this->reader->read() && $this->reader->name !== 'product') { } }
public function getRows($maxCount = 1000) { $this->ensureMaxCountIsValid($maxCount); $result = []; $count = 0; while ($count < $maxCount && $this->reader->read()) { if ($this->checkIsNodeAccepted($this->reader->name)) { $result[] = $this->getRowAttributes(); ++$count; } } return $result; }
/** * Deserialize the resource from the specified input stream. * * @param string $incoming The text to deserialize. * * @return mixed the resource. */ public function deserialize($incoming) { $resources = null; $reader = new \XMLReader(); $reader->xml($incoming); $reader->read(); do { if ($reader->nodeType == \XMLReader::ELEMENT && XmlMapper::isKnownType($reader->name)) { $class = XmlMapper::getClassName($reader->name); $resources[] = new $class($reader); } } while ($reader->read()); return $resources; }
protected function parseEntrypoints(\XMLReader $xml, InfosAbstract $object) { $property = $xml->name; while ($xml->read()) { if ($xml->nodeType == \XMLReader::END_ELEMENT && 'entrypoints' == $xml->name) { break; } if ($xml->nodeType == \XMLReader::ELEMENT) { $id = $config = ''; $type = 'classic'; while ($xml->moveToNextAttribute()) { if ($xml->name == 'file') { $id = $xml->value; } else { if ($xml->name == 'config') { $config = $xml->value; } else { if ($xml->name == 'type') { $type = $xml->value; } } } } if ($id) { if (strpos($id, '.php') === false) { $id .= '.php'; } $object->entrypoints[$id] = array('config' => $config, 'file' => $id, 'type' => $type); } } } }
/** * Function takes path to SVG font (local path) and processes its xml * to get path representation of every character and additional * font parameters */ public function load($filename) { $this->glyphs = array(); $z = new XMLReader(); $z->open($filename); // move to the first <product /> node while ($z->read()) { $name = $z->name; if ($z->nodeType == XMLReader::ELEMENT) { if ($name == 'font') { $this->id = $z->getAttribute('id'); $this->horizAdvX = $z->getAttribute('horiz-adv-x'); } if ($name == 'font-face') { $this->unitsPerEm = $z->getAttribute('units-per-em'); $this->ascent = $z->getAttribute('ascent'); $this->descent = $z->getAttribute('descent'); } if ($name == 'glyph') { $unicode = $z->getAttribute('unicode'); $unicode = $this->utf8ToUnicode($unicode); $unicode = $unicode[0]; $this->glyphs[$unicode] = new stdClass(); $this->glyphs[$unicode]->horizAdvX = $z->getAttribute('horiz-adv-x'); if (empty($this->glyphs[$unicode]->horizAdvX)) { $this->glyphs[$unicode]->horizAdvX = $this->horizAdvX; } $this->glyphs[$unicode]->d = $z->getAttribute('d'); } } } }
protected function runRestoreFromXML($strRestoreFile) { // Unzip XML $objGzFile = gzopen(TL_ROOT . "/" . $strRestoreFile, "r"); $objXMLFile = new File("system/tmp/" . basename($strRestoreFile) . ".xml"); $objXMLFile->write(""); $objXMLFile->close(); while (true) { $strConten = gzread($objGzFile, 500000); if ($strConten == false || empty($strConten)) { break; } $objXMLFile->append($strConten, ""); $objXMLFile->close(); } // Read XML $this->objXMLReader = new XMLReader(); $this->objXMLReader->open(TL_ROOT . "/system/tmp/" . basename($strRestoreFile) . ".xml"); while ($this->objXMLReader->read()) { switch ($this->objXMLReader->nodeType) { case XMLReader::ELEMENT: switch ($this->objXMLReader->localName) { case "structure": $arrRestoreTables = $this->doRestoreStructure(); break; case "data": $this->doRestoreData(); break; } break; } } $objXMLFile->delete(); return $arrRestoreTables; }
public static function generateAcronymInfo($filename) { static $info; if ($info) { return $info; } if (!is_file($filename)) { v("Can't find acronym file (%s), skipping", $filename, E_USER_WARNING); return array(); } $r = new \XMLReader(); if (!$r->open($filename)) { v("Could not open file for accessing acronym information (%s)", $filename, E_USER_ERROR); } $acronyms = array(); while ($r->read()) { if ($r->nodeType != \XMLReader::ELEMENT) { continue; } if ($r->name == "term") { $r->read(); $k = $r->value; $acronyms[$k] = ""; } else { if ($r->name == "simpara") { $r->read(); $acronyms[$k] = $r->value; } } } $info = $acronyms; return $acronyms; }
protected function _convertBook() { if (!($this->_reader->name == 'book' && $this->_reader->nodeType == XMLReader::ELEMENT)) { throw new ErrorException("Unexpected XML reader position, expecting a book element"); } $title = $this->_reader->getAttribute('title'); $this->_writer->startElement('folder'); $this->_writer->writeElement('title', $title); while ($this->_reader->read()) { if ($this->_reader->nodeType == XMLReader::END_ELEMENT && $this->_reader->name == 'book') { break; // Done reading book element } if ($this->_reader->nodeType == XMLReader::ELEMENT) { switch ($this->_reader->name) { case 'page': $this->_convertPage(); break; case 'book': $this->_convertBook(); break; } } } $this->_writer->endElement(); // End <folder> element }
/** * Parse the passed in Sparql XML string into a more easily usable format. * * @param string $sparql * A string containing Sparql result XML. * * @return array * Indexed (numerical) array, containing a number of associative arrays, * with keys being the same as the variable names in the query. * URIs beginning with 'info:fedora/' will have this beginning stripped * off, to facilitate their use as PIDs. */ public static function parseSparqlResults($sparql) { // Load the results into a XMLReader Object. $xmlReader = new XMLReader(); $xmlReader->xml($sparql); // Storage. $results = array(); // Build the results. while ($xmlReader->read()) { if ($xmlReader->localName === 'result') { if ($xmlReader->nodeType == XMLReader::ELEMENT) { // Initialize a single result. $r = array(); } elseif ($xmlReader->nodeType == XMLReader::END_ELEMENT) { // Add result to results $results[] = $r; } } elseif ($xmlReader->nodeType == XMLReader::ELEMENT && $xmlReader->depth == 3) { $val = array(); $uri = $xmlReader->getAttribute('uri'); if ($uri !== NULL) { $val['value'] = self::pidUriToBarePid($uri); $val['uri'] = (string) $uri; $val['type'] = 'pid'; } else { //deal with any other types $val['type'] = 'literal'; $val['value'] = (string) $xmlReader->readInnerXML(); } $r[$xmlReader->localName] = $val; } } $xmlReader->close(); return $results; }
/** * Method to load a URI into the feed reader for parsing. * * @param string $uri The URI of the feed to load. Idn uris must be passed already converted to punycode. * * @return JFeedReader * * @since 12.3 * @throws InvalidArgumentException * @throws RuntimeException */ public function getFeed($uri) { // Create the XMLReader object. $reader = new XMLReader(); // Open the URI within the stream reader. if (!@$reader->open($uri, null, LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING)) { // Retry with JHttpFactory that allow using CURL and Sockets as alternative method when available // Adding a valid user agent string, otherwise some feed-servers returning an error $options = new \joomla\Registry\Registry(); $options->set('userAgent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0'); $connector = JHttpFactory::getHttp($options); $feed = $connector->get($uri); if ($feed->code != 200) { throw new RuntimeException('Unable to open the feed.'); } // Set the value to the XMLReader parser if (!$reader->xml($feed->body, null, LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING)) { throw new RuntimeException('Unable to parse the feed.'); } } try { // Skip ahead to the root node. while ($reader->read()) { if ($reader->nodeType == XMLReader::ELEMENT) { break; } } } catch (Exception $e) { throw new RuntimeException('Error reading feed.', $e->getCode(), $e); } // Setup the appopriate feed parser for the feed. $parser = $this->_fetchFeedParser($reader->name, $reader); return $parser->parse(); }
/** * Method to load a URI into the feed reader for parsing. * * @param string $uri The URI of the feed to load. Idn uris must be passed already converted to punycode. * * @return JFeedReader * * @since 12.3 * @throws InvalidArgumentException * @throws RuntimeException */ public function getFeed($uri) { // Create the XMLReader object. $reader = new XMLReader(); // Open the URI within the stream reader. if (!@$reader->open($uri, null, LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING)) { // If allow_url_fopen is enabled if (ini_get('allow_url_fopen')) { // This is an error throw new RuntimeException('Unable to open the feed.'); } else { // Retry with JHttpFactory that allow using CURL and Sockets as alternative method when available $connector = JHttpFactory::getHttp(); $feed = $connector->get($uri); // Set the value to the XMLReader parser if (!$reader->xml($feed->body, null, LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING)) { throw new RuntimeException('Unable to parse the feed.'); } } } try { // Skip ahead to the root node. while ($reader->read()) { if ($reader->nodeType == XMLReader::ELEMENT) { break; } } } catch (Exception $e) { throw new RuntimeException('Error reading feed.'); } // Setup the appopriate feed parser for the feed. $parser = $this->_fetchFeedParser($reader->name, $reader); return $parser->parse(); }
/** * Tests JFeedParser::moveToClosingElement() with self-closing tags. * * @return void * * @since 12.3 */ public function testMoveToClosingElementWithSelfClosingTag() { // Set the XML for the internal reader and move the stream to the first <node> element. $this->_reader->Xml('<root><node test="first" /><node test="second"></node></root>'); // Advance the reader to the first <node> element. do { $this->_reader->read(); } while ($this->_reader->name != 'node'); // Ensure that the current node is <node test="first">. $this->assertEquals(XMLReader::ELEMENT, $this->_reader->nodeType); $this->assertEquals('node', $this->_reader->name); $this->assertEquals('first', $this->_reader->getAttribute('test')); // Move to the closing element, which should be </node>. TestReflection::invoke($this->_instance, 'moveToClosingElement'); $this->assertEquals(true, $this->_reader->isEmptyElement); $this->assertEquals('node', $this->_reader->name); // Advance the reader to the next element. do { $this->_reader->read(); } while ($this->_reader->nodeType != XMLReader::ELEMENT); // Ensure that the current node is <node test="first">. $this->assertEquals(XMLReader::ELEMENT, $this->_reader->nodeType); $this->assertEquals('node', $this->_reader->name); $this->assertEquals('second', $this->_reader->getAttribute('test')); }
function eol_xml_stats() { $path = "http://localhost/eol_php_code/applications/content_server/resources/218.xml"; $reader = new \XMLReader(); $reader->open($path); $i = 0; $dist_count = 0; $taxa_count = 0; while (@$reader->read()) { if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "taxon") { $string = $reader->readOuterXML(); $string = str_ireplace("dc:", "dc_", $string); $string = str_ireplace("dwc:", "dwc_", $string); if ($xml = simplexml_load_string($string)) { $taxa_with_dist = false; $taxon_id = (string) $xml->dc_identifier; print "[{$taxon_id}]"; foreach ($xml->dataObject as $o) { if (@$o->subject == "http://rs.tdwg.org/ontology/voc/SPMInfoItems#Distribution") { $dist_count++; $taxa_with_dist = true; } } if ($taxa_with_dist) { $taxa_count++; } } } } print "\n\n"; print "\n distribution: [{$dist_count}]"; print "\n taxa with dist: [" . $taxa_count . "]"; print "\n\n"; }
/** * Method to load a URI into the feed reader for parsing. * * @param string $uri The URI of the feed to load. * * @return JFeedReader * * @since 3.0 * @throws InvalidArgumentException * @throws RuntimeException */ public function getFeed($uri) { // Make sure the file exists. try { $this->http->get($uri); } catch (RunTimeException $e) { throw new InvalidArgumentException('The file ' . $uri . ' does not exist.'); } // Create the XMLReader object. $reader = new XMLReader(); // Open the URI within the stream reader. if (!@$reader->open($uri, null, LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING)) { throw new RuntimeException('Unable to open the feed.'); } try { // Skip ahead to the root node. while ($reader->read() && $reader->nodeType !== XMLReader::ELEMENT) { } } catch (Exception $e) { throw new RuntimeException('Error reading feed.'); } // Setup the appopriate feed parser for the feed. $parser = $this->_fetchFeedParser($reader->name, $reader); return $parser->parse(); }
public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL) { $this->succeed = FALSE; $xmlReader = new \XMLReader(); try { $xmlReader->XML($content); while ($xmlReader->read()) { if ($xmlReader->nodeType == \XMLReader::ELEMENT) { switch ($xmlReader->name) { case Constants::ERROR: $this->parseNormalErrorResponse($xmlReader); break; default: // case Constants::Messages $this->parseBatchSendErrorResponse($xmlReader); break; } } } } catch (\Exception $e) { if ($exception != NULL) { throw $exception; } elseif ($e instanceof MnsException) { throw $e; } else { throw new MnsException($statusCode, $e->getMessage()); } } catch (\Throwable $t) { throw new MnsException($statusCode, $t->getMessage()); } }
public function actionFias() { $file = 'AS_ADDROBJ_20160609_c5080ba4-9f46-4b6e-aecc-72a630730b3a.XML'; $interestingNodes = array('AOGUID'); $xmlObject = new \XMLReader(); $xmlObject->open($file); header('Content-Type: text/html; charset=utf-8'); $i = 0; while ($xmlObject->read()) { if ($xmlObject->name == 'Object') { if ($xmlObject->getAttribute('IFNSFL') == '8603') { // if (($xmlObject->getAttribute('PARENTGUID') == '0bf0f4ed-13f8-446e-82f6-325498808076' && $xmlObject->getAttribute('AOLEVEL') == '7') || $xmlObject->getAttribute('AOGUID') == '0bf0f4ed-13f8-446e-82f6-325498808076') { $fias = new Fias(); $fias->AOGUID = $xmlObject->getAttribute('AOGUID'); $fias->OFFNAME = $xmlObject->getAttribute('OFFNAME'); $fias->SHORTNAME = $xmlObject->getAttribute('SHORTNAME'); $fias->IFNSFL = $xmlObject->getAttribute('IFNSFL'); $fias->AOLEVEL = $xmlObject->getAttribute('AOLEVEL'); $fias->PARENTGUID = $xmlObject->getAttribute('PARENTGUID'); if ($fias->validate()) { $fias->save(); } else { var_dump($fias->attributes); var_dump($fias->getErrors()); } // $i++; } } } echo 'ok'; $xmlObject->close(); }
/** * Reads the configuration file and creates the class attributes * */ protected function initialize() { $reader = new XMLReader(); $reader->open(parent::getConfigFilePath()); $reader->setRelaxNGSchemaSource(self::WURFL_CONF_SCHEMA); libxml_use_internal_errors(TRUE); while ($reader->read()) { if (!$reader->isValid()) { throw new Exception(libxml_get_last_error()->message); } $name = $reader->name; switch ($reader->nodeType) { case XMLReader::ELEMENT: $this->_handleStartElement($name); break; case XMLReader::TEXT: $this->_handleTextElement($reader->value); break; case XMLReader::END_ELEMENT: $this->_handleEndElement($name); break; } } $reader->close(); if (isset($this->cache["dir"])) { $this->logDir = $this->cache["dir"]; } }