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()); } }
} // 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===
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();
public function moveToAttributeNo($index) { return parent::moveToAttributeNo($index); }