function getCoOrdinates($output, $reference) { $bookList = array(); $i = 0; $xmlReader = new XMLReader(); $xmlReader->xml($output); while ($xmlReader->read()) { // check to ensure nodeType is an Element not attribute or #Text if ($xmlReader->nodeType == XMLReader::ELEMENT) { if ($xmlReader->localName == $reference[0]) { $bookList[$i][$reference[1]] = $xmlReader->getAttribute($reference[1]); $bookList[$i][$reference[2]] = $xmlReader->getAttribute($reference[2]); } if ($xmlReader->localName == 'coordinates') { // move to its textnode / child $xmlReader->read(); $allCosNele = $xmlReader->value; $allCosNele = explode(',', $allCosNele); $bookList[$i]['coordinates']['lon'] = $allCosNele[0]; $bookList[$i]['coordinates']['lat'] = $allCosNele[1]; $bookList[$i]['coordinates']['elevation'] = $allCosNele[2]; $i = $i + 1; } } } //print_r($bookList); return $bookList; }
protected function readNext(XMLReader $reader) { do { if ($this->isStartElement('ancode')) { $pos_id = (int) $reader->getAttribute('pos_id'); if (!isset($this->poses[$pos_id])) { throw new Exception("Invalid pos id '{$pos_id}' found in ancode '" . $reader->getAttribute('id') . "'"); } $pos = $this->poses[$pos_id]; $ancode = new phpMorphy_Dict_Ancode($reader->getAttribute('id'), $pos['name'], $pos['is_predict']); while ($this->read()) { if ($this->isStartElement('grammem')) { $grammem_id = (int) $reader->getAttribute('id'); if (!isset($this->grammems[$grammem_id])) { throw new Exception("Invalid grammem id '{$grammem_id}' found in ancode '" . $ancode->getId() . "'"); } $ancode->addGrammem($this->grammems[$grammem_id]['name']); } elseif ($this->isEndElement('ancode')) { break; } } unset($this->current); $this->current = $ancode; break; } } while ($this->read()); }
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; }
protected function readNext(XMLReader $reader) { do { if ($this->isStartElement('pos')) { $this->current = array('id' => (int) $reader->getAttribute('id'), 'name' => $reader->getAttribute('name'), 'is_predict' => (bool) $reader->getAttribute('is_predict')); $this->read(); break; } } while ($this->read()); }
protected function parseElement(\XMLReader $reader) { if ($reader->name === 'color') { $name = $reader->getAttribute('name'); $hex = $reader->getAttribute('hex'); if (!$name || !$hex) { throw new ParseException('"name" and "hex" attributes are required for "color" tag.'); } $root =& $this->getFirstElementFromStack(); $root[$name] = $hex; } }
public function getTrustedIdentityProviderUrl($name, $replyUrl) { $xml = new XMLReader(); $xml->open($this->repositoryFileName); $trustedIssuers = array(); while ($xml->read()) { if ($xml->nodeType == XMLReader::ELEMENT && $xml->name == "issuer" && $xml->getAttribute("name") == $name) { return new TrustedIssuer($xml->getAttribute("name"), $xml->getAttribute("displayName"), $xml->getAttribute("realm"), $replyUrl); } } return null; }
protected function parseElement(\XMLReader $reader) { if ($reader->name === self::COMPLEX_ATTRIBUTE_TAG) { $root = $this->getLastElementFromStack(); $name = trim($reader->getAttribute('name')); $class = trim($reader->getAttribute('class')); if (!$name || !$class) { throw new ParseException('"name" and "class" attributes are required.'); } $root->addDefinition($name, $class); } }
/** * 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'); } } } }
private function getCurrencyExchangeRates(\XMLReader $xml) { switch ($xml->localName) { case 'Cube': $this->currencyDetails['CXD'] = strtotime($xml->getAttribute('date')); break; case 'Rate': $multiplier = 1; if (!is_null($xml->getAttribute('multiplier'))) { $multiplier = $xml->getAttribute('multiplier'); } $this->currencyDetails['CXV'][$xml->getAttribute('currency')] = $xml->readInnerXml() / $multiplier; break; } }
/** * 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; }
/** * 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 getClioNum($appurl, $link) { $clio = $current = $currentA = ""; $reader = new XMLReader(); $clioQ = $appurl . '/getSingleStuff.xq?doc=' . $link . '_ead.xml§ion=summary'; $reader->open($clioQ); while ($reader->read()) { if ($reader->name == "unitid" && $reader->getAttribute("type") == "clio") { if ($reader->nodeType == XMLReader::ELEMENT) { $currentA = "clio"; } else { if ($reader->nodeType == XMLReader::END_ELEMENT) { $currentA = ""; } } } //echo "{$reader->name} and $currentA<br />"; if ($reader->name == "#text" && $currentA == "clio") { $clio = $reader->value; // there can be only one } } // end WHILE $reader->close(); return $clio; }
/** * 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); }
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 }
public function create() { $database_logs = Database_Logs::getInstance(); Database_SQLite::exec($this->db, "PRAGMA temp_store = MEMORY;"); Database_SQLite::exec($this->db, "PRAGMA synchronous = OFF;"); Database_SQLite::exec($this->db, "PRAGMA journal_mode = OFF;"); $sql = <<<'EOD' CREATE TABLE IF NOT EXISTS morphhb ( book integer, chapter integer, verse integer, hebrew text ); EOD; Database_SQLite::exec($this->db, $sql); $books = array("Gen", "Exod", "Lev", "Num", "Deut", "Josh", "Judg", "Ruth", "1Sam", "2Sam", "1Kgs", "2Kgs", "1Chr", "2Chr", "Ezra", "Neh", "Esth", "Job", "Ps", "Prov", "Eccl", "Song", "Isa", "Jer", "Lam", "Ezek", "Dan", "Hos", "Joel", "Amos", "Obad", "Jonah", "Mic", "Nah", "Hab", "Zeph", "Hag", "Zech", "Mal"); foreach ($books as $book => $osis) { $book++; $database_logs->log("Importing Hebrew data for {$book} {$osis}"); $xml = new XMLReader(); $xml->open("../morphhb/{$osis}.xml"); $chapter = 0; $verse = 0; $word = false; $hebrew = ""; while ($xml->read()) { $nodeType = $xml->nodeType; $name = $xml->name; if ($nodeType == XMLReader::ELEMENT) { if ($name == "verse") { $osisID = $xml->getAttribute("osisID"); $osisID = explode(".", $osisID); $chapter = intval($osisID[1]); $verse = intval($osisID[2]); } if ($name == "w") { $word = true; } } if ($nodeType == XMLReader::TEXT) { if ($word) { $hebrew = $xml->value; $hebrew = trim($hebrew); $hebrew = str_replace("/", "", $hebrew); $hebrew = str_replace("'", "''", $hebrew); $sql = "INSERT INTO morphhb (book, chapter, verse, hebrew) VALUES ({$book}, {$chapter}, {$verse}, '{$hebrew}');"; Database_SQLite::exec($this->db, $sql); } } if ($nodeType == XMLReader::END_ELEMENT) { if ($name == "w") { $word = false; } } } $xml->close(); } }
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(); }
private function getRowAttributes() { $result = []; foreach ($this->attributes as $attribute) { // Если атрибут отсутствует, в $result[$attribute] окажется null, также передаем null вместо пустого значения $result[$attribute] = $this->reader->getAttribute($attribute) ?: null; } return $result; }
protected function readNext(XMLReader $reader) { do { if ($this->isStartElement('flexia_model')) { $flexia_model = new phpMorphy_Dict_FlexiaModel($reader->getAttribute('id')); while ($this->read()) { if ($this->isStartElement('flexia')) { $flexia_model->append(new phpMorphy_Dict_Flexia($reader->getAttribute('prefix'), $reader->getAttribute('suffix'), $reader->getAttribute('ancode_id'))); } elseif ($this->isEndElement('flexia_model')) { break; } } unset($this->current); $this->current = $flexia_model; break; } } while ($this->read()); }
protected function readNext(XMLReader $reader) { do { if ($this->isStartElement('prefix_model')) { $prefix_model = new phpMorphy_Dict_PrefixSet($reader->getAttribute('id')); while ($this->read()) { if ($this->isStartElement('prefix')) { $prefix_model->append($reader->getAttribute('value')); } elseif ($this->isEndElement('prefix_model')) { break; } } unset($this->current); $this->current = $prefix_model; break; } } while ($this->read()); }
private function createFont(\XMLReader $reader, $name, $style) { $src = $reader->getAttribute('src'); if ($src) { $font = $src; } else { throw new ParseException(sprintf('File or type attribute are required in font "%s: %s" definition.', $name, $style)); } return $font; }
public function XMLin($file) { $gpxDocument = new XMLReader(); $gpxDocument->open($file); $gpxDocument->read(); if ($gpxDocument->name != "gpx") { echo "The top node of the GPX document must be GPX"; return false; } $this->version = $gpxDocument->getAttribute("version"); $this->creator = $gpxDocument->getAttribute("creator"); $this->readToNextOpen($gpxDocument); if ($gpxDocument->name == "metadata") { $this->metadata = new GPXMetadata(); $this->metadata->XMLin($gpxDocument); $this->readToNextOpen($gpxDocument); } if ($gpxDocument->name == "wpt") { $wptCount = 0; do { $this->waypoints[$wptCount] = new GPXWaypoint(); $this->waypoints[$wptCount]->XMLin($gpxDocument); $wptCount++; } while ($gpxDocument->name == "wpt"); } if ($gpxDocument->name == "rte") { $rteCount = 0; do { $this->routes[$rteCount] = new GPXRoute(); $this->routes[$rteCount]->XMLin($gpxDocument); $rteCount++; } while ($gpxDocument->name == "rte"); } if ($gpxDocument->name == "trk") { $trkCount = 0; do { $this->tracks[$trkCount] = new GPXTrack(); $this->tracks[$trkCount]->XMLin($gpxDocument); $trkCount++; } while ($gpxDocument->name == "trk"); } }
protected function readNext(XMLReader $reader) { do { if ($this->isStartElement('lemma')) { unset($this->current); $this->current = new phpMorphy_Dict_Lemma($reader->getAttribute('base'), $reader->getAttribute('flexia_id'), 0); $prefix_id = $reader->getAttribute('prefix_id'); $ancode_id = $reader->getAttribute('ancode_id'); if (!is_null($prefix_id)) { $this->current->setPrefixId($prefix_id); } if (!is_null($ancode_id)) { $this->current->setAncodeId($ancode_id); } $this->count++; $this->read(); break; } } while ($this->read()); }
protected function readNext(XMLReader $reader) { do { if ($this->isStartElement('locale')) { if (!($this->current = $reader->getAttribute('name'))) { throw new Exception('Empty locale name found'); } $this->read(); break; } } while ($this->read()); }
/** * Returns the list of worksheets inside the archive * * The keys of the array should be the titles of the worksheets * The values of the array are the names of the XML worksheet files inside the archive * * @param Relationships $relationships * @param string $path * * @return array */ public function getWorksheetPaths(Relationships $relationships, $path) { $xml = new \XMLReader(); $xml->open($path); $paths = []; while ($xml->read()) { if (\XMLReader::ELEMENT === $xml->nodeType && 'sheet' === $xml->name) { $rId = $xml->getAttributeNs('id', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $paths[$xml->getAttribute('name')] = $relationships->getWorksheetPath($rId); } } return $paths; }
protected function parseInfo(XMLReader $xml, $object) { if (XMLReader::ELEMENT == $xml->nodeType && 'info' == $xml->name) { $object->id = $xml->getAttribute('id'); $object->name = $xml->getAttribute('name'); $object->createDate = $xml->getAttribute('createdate'); $gJConfig = jApp::config(); 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') == $gJConfig->locale) { $xml->read(); $object->{$property} = $xml->value; } } elseif ('creator' == $property || 'contributor' == $property) { $person = array(); while ($xml->moveToNextAttribute()) { $attrName = $xml->name; $person[$attrName] = $xml->value; } $property .= 's'; array_push($object->{$property}, $person); } else { while ($xml->moveToNextAttribute()) { $attrProperty = $property . ucfirst($xml->name); $object->{$attrProperty} = $xml->value; } $xml->read(); $object->{$property} = $xml->value; } } } } return $object; }
/** * Creates a Map of devices from the xml file * * @param string $fileName path to the xml file to parse * @return Map of <deviceId ModelDevice> */ public static function parse($fileName, $validationSchema) { $devicesMap = array(); $deviceID = null; $groupID = null; $reader = new XMLReader(); $reader->open($fileName); $fullFileName = dirname(__FILE__) . DIRECTORY_SEPARATOR . $validationSchema; $reader->setRelaxNGSchema($fullFileName); libxml_use_internal_errors(TRUE); while ($reader->read()) { if (!$reader->isValid()) { throw new Exception(libxml_get_last_error()->message); } $nodeName = $reader->name; switch ($reader->nodeType) { case XMLReader::ELEMENT: switch ($nodeName) { case WURFL_Xml_Interface::DEVICE: $groupIDCapabilitiesMap = array(); $deviceID = $reader->getAttribute(WURFL_Xml_Interface::ID); $userAgent = $reader->getAttribute(WURFL_Xml_Interface::USER_AGENT); $fallBack = $reader->getAttribute(WURFL_Xml_Interface::FALL_BACK); $actualDeviceRoot = $reader->getAttribute(WURFL_Xml_Interface::ACTUAL_DEVICE_ROOT); $currentCapabilityNameValue = array(); if ($reader->isEmptyElement) { $device = new WURFL_Xml_ModelDevice($deviceID, $userAgent, $fallBack, $actualDeviceRoot); $devicesMap[$deviceID] = $device; } break; case WURFL_Xml_Interface::GROUP: $groupID = $reader->getAttribute(WURFL_Xml_Interface::GROUP_ID); $groupIDCapabilitiesMap[$groupID] = array(); break; case WURFL_Xml_Interface::CAPABILITY: $capabilityName = $reader->getAttribute(WURFL_Xml_Interface::CAPABILITY_NAME); $capabilityValue = $reader->getAttribute(WURFL_Xml_Interface::CAPABILITY_VALUE); $currentCapabilityNameValue[$capabilityName] = $capabilityValue; $groupIDCapabilitiesMap[$groupID][$capabilityName] = $capabilityValue; break; } break; case XMLReader::END_ELEMENT: if ($nodeName == WURFL_Xml_Interface::DEVICE) { $device = new WURFL_Xml_ModelDevice($deviceID, $userAgent, $fallBack, $actualDeviceRoot, $groupIDCapabilitiesMap); $devicesMap[$device->id] = $device; } break; } } // end of while $reader->close(); return $devicesMap; }
/** * @param \XMLReader $xml an XML document to be transformed to GitHub Markdown * @return String */ protected function processXml($xml) { $output = ''; // states $inLink = false; /** * Mapping of elements which just append additional markup to the text */ $appendersMap = [self::NODE_HR => '----', self::NODE_BR => "\n", self::NODE_H1 => 'h1. ', self::NODE_H2 => 'h2. ', self::NODE_H3 => 'h3. ', self::NODE_H4 => 'h4. ', self::NODE_H5 => 'h5. ', self::NODE_H6 => 'h6. ', self::NODE_BLOCKQUOTE => 'bq. ']; /** * Mapping of elements which wrap text with additional markup */ $wrappersMap = [self::NODE_EMPHASIZED => '_', self::NODE_STRONG => '*']; while ($xml->read()) { // if it's a beginning of new paragraph just continue if ($xml->nodeType === \XMLReader::ELEMENT && $xml->name === self::NODE_PARAGRAPH) { continue; } // if it's an ending of a paragraph add newlines if ($xml->nodeType === \XMLReader::END_ELEMENT && $xml->name === self::NODE_PARAGRAPH) { $output .= "\n\n"; } // take care of wrapping nodes if (in_array($xml->name, array_keys($wrappersMap))) { $output .= $wrappersMap[$xml->name]; } // take care of nodes which just append things to their text if (in_array($xml->name, array_keys($appendersMap)) && $xml->nodeType !== \XMLReader::END_ELEMENT) { $output .= $appendersMap[$xml->name]; } // links if ($xml->name === self::NODE_A && $xml->nodeType !== \XMLReader::END_ELEMENT) { $output .= '['; $inLink = true; } if ($xml->name === self::NODE_A && $xml->nodeType === \XMLReader::END_ELEMENT) { $output .= $xml->getAttribute('href') . ']'; $inLink = false; } // just add the text if ($xml->nodeType === \XMLReader::TEXT) { $text = $xml->readString(); if ($inLink && !empty($text)) { $output .= $text . '|'; } else { $output .= $text; } } } return trim($output); }
/** * Parses a MySQL dump XML file. * * @param $source * @return Fixture */ public function parse($source) { try { return parent::parse($source); } catch (InvalidParserException $e) { $z = new \XMLReader(); $z->open($source); while ($z->read() && $z->name !== 'table_data') { } $tableName = $z->getAttribute('name'); $fixtureArray[$tableName] = []; return Fixture::create($fixtureArray); } }
public function show_weather() { $citycode = '1252376'; $temptype = 'c'; $url = 'http://xml.weather.yahoo.com/forecastrss?w=' . $citycode . '&u=' . $temptype; //$xml = file_get_contents($url); $reader = new \XMLReader(); $reader->open($url, 'utf-8'); while ($reader->read()) { if ($reader->name == 'yweather:condition') { $code = $reader->getAttribute('code'); //获取天气代码 $temp = $reader->getAttribute('temp'); //获取温度 } if ($reader->name == 'yweather:atmosphere') { $humi = $reader->getAttribute('humidity'); //获取湿度 } if ($reader->name == 'yweather:wind') { $wind = $reader->getAttribute('speed'); //获取湿度 } if ($reader->name == 'yweather:forecast') { $weekinfo[$reader->getAttribute('day')] = array($reader->getAttribute('low'), $reader->getAttribute('high'), $reader->getAttribute('code')); } } $reader->close(); $weatherinfo = $this->code2char($code); //".$wind."Km/h $article[0] = array('Title' => "[今天] 岘港 " . $weatherinfo[0] . " " . $temp . "℃", 'Description' => "[今天] 白天: 夜间:\n[明天] 白天: 夜间:", 'PicUrl' => 'http://b2b.gzl.com.cn/Administrator/UploadFile/Editor/Image/2011/10/20111024142542174.jpg', 'Url' => $this->create_loginurl('show_weather')); if (!empty($weekinfo)) { $week_cn = array('Thu' => '星期四', 'Fri' => '星期五', 'Sat' => '星期六', 'Sun' => '星期日', 'Mon' => '星期一', 'Tue' => '星期二', 'Wed' => '星期三'); $i = 1; foreach ($weekinfo as $key => $value) { $week_info = array(); $week_info = $this->code2char($value[2] - 1); $article[$i++] = array('Title' => $week_cn[$key] . " " . $week_info[0] . "\n最高:" . $value[1] . "℃ 最低:" . $value[0] . "℃", 'Description' => "岘港天气", 'PicUrl' => $week_info[1], 'Url' => $this->create_loginurl('show_weather')); } } $this->news($article); }
function get_locale($xml) { $reader = new XMLReader(); if (false === $reader->open($xml)) { return false; } while ($reader->read()) { if ($reader->nodeType == XMLReader::ELEMENT) { if ($reader->localName === 'locale') { $result = $reader->getAttribute('name'); $result = strlen($result) ? $result : false; break; } } } $reader->close(); return $result; }