本文整理汇总了PHP中XMLReader::moveToAttributeNo方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLReader::moveToAttributeNo方法的具体用法?PHP XMLReader::moveToAttributeNo怎么用?PHP XMLReader::moveToAttributeNo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLReader
的用法示例。
在下文中一共展示了XMLReader::moveToAttributeNo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: readDump
function readDump()
{
$state = '';
$lastName = '';
$this->thisPage = 0;
$this->thisRev = 0;
$reader = new XMLReader();
$reader->open($this->input);
$writer = new XMLWriter();
$writer->openMemory();
while ($reader->read()) {
$tag = $reader->name;
$type = $reader->nodeType;
if ($type == XmlReader::END_ELEMENT) {
$writer->endElement();
if ($tag == 'revision') {
$this->revCount();
$this->thisRev = '';
} elseif ($tag == 'page') {
$this->reportPage();
$this->thisPage = '';
}
} elseif ($type == XmlReader::ELEMENT) {
$attribs = array();
if ($reader->hasAttributes) {
for ($i = 0; $reader->moveToAttributeNo($i); $i++) {
$attribs[$reader->name] = $reader->value;
}
}
if ($reader->isEmptyElement && $tag == 'text' && isset($attribs['id'])) {
$writer->startElement('text');
$writer->writeAttribute('xml:space', 'preserve');
$text = $this->getText($attribs['id']);
if (strlen($text)) {
$writer->text($text);
}
$writer->endElement();
} else {
$writer->startElement($tag);
foreach ($attribs as $name => $val) {
$writer->writeAttribute($name, $val);
}
if ($reader->isEmptyElement) {
$writer->endElement();
}
}
$lastName = $tag;
if ($tag == 'revision') {
$state = 'revision';
} elseif ($tag == 'page') {
$state = 'page';
}
} elseif ($type == XMLReader::SIGNIFICANT_WHITESPACE || ($type = XMLReader::TEXT)) {
if ($lastName == 'id') {
if ($state == 'revision') {
$this->thisRev .= $reader->value;
} elseif ($state == 'page') {
$this->thisPage .= $reader->value;
}
}
$writer->text($reader->value);
}
$this->sink->write($writer->outputMemory());
}
}
示例2:
}
// Named attribute
$attr = $reader->moveToAttribute('num');
echo $reader->name . ": ";
echo $reader->value . "\n";
if ($reader->getAttribute('num') == $reader->value) {
echo "attr num failed\n";
}
$attr = $reader->moveToAttribute('idx');
echo $reader->name . ": ";
echo $reader->value . "\n";
if ($reader->getAttribute('idx') == $reader->value) {
echo "attr idx failed\n";
}
// Numeric positions of attributes
$attr = $reader->moveToAttributeNo(0);
echo $reader->name . ": ";
echo $reader->value . "\n";
if ($reader->getAttributeNo(0) == $reader->value) {
echo "attr 0 failed\n";
}
$attr = $reader->moveToAttributeNo(1);
echo $reader->name . ": ";
echo $reader->value . "\n";
}
}
}
$reader->close();
unlink($filename);
?>
===DONE===
示例3: while
while ($owl->nodeType != XMLReader::END_ELEMENT || $owl->name != "owl:Ontology") {
if ($owl->nodeType == XMLReader::ELEMENT) {
// This is the switch statement below that can be written instead of the if logic statement for foaf:homepage
// It determines the specific name of the element
switch ($owl->name) {
case 'foaf:homepage':
break;
case 'dc:title':
break;
case 'dc:description':
break;
}
}
if ($owl->name == "foaf:homepage" && $owl->nodeType == XMLReader::ELEMENT) {
for ($n = 0; $n < $owl->attributeCount; $n++) {
$owl->moveToAttributeNo($n);
print $owl->name . ' = "' . $owl->value . "\"\n";
}
$owl->read();
print $owl->value . "\n";
}
$owl->read();
}
}
if ($owl->nodeType == XMLReader::ELEMENT && $owl->name == "rdf:Description") {
while ($owl->nodeType != XMLReader::END_ELEMENT || $owl->name != "rdf:Description") {
if ($owl->nodeType == XMLReader::ELEMENT) {
print "ELEMENT" . $owl->name . "\n";
if ($owl->hasAttributes && $owl->nodeType == XMLReader::ELEMENT) {
for ($n = 0; $n < $owl->attributeCount; $n++) {
$owl->moveToFirstAttribute();
示例4: moveToAttributeNo
public function moveToAttributeNo($index)
{
return parent::moveToAttributeNo($index);
}