本文整理汇总了PHP中XMLReader::getAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLReader::getAttribute方法的具体用法?PHP XMLReader::getAttribute怎么用?PHP XMLReader::getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLReader
的用法示例。
在下文中一共展示了XMLReader::getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCoOrdinates
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;
}
示例2: readNext
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());
}
示例3: parseInfo
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;
}
示例4: readNext
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());
}
示例5: parseElement
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;
}
}
示例6: getTrustedIdentityProviderUrl
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;
}
示例7: parseElement
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);
}
}
示例8: load
/**
* 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');
}
}
}
}
示例9: getCurrencyExchangeRates
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;
}
}
示例10: parseSparqlResults
/**
* 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;
}
示例11: testMoveToClosingElementWithSelfClosingTag
/**
* 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'));
}
示例12: getClioNum
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;
}
示例13: parse
/**
* 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);
}
示例14: _convertBook
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
}
示例15: create
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();
}
}