
<?php Array ( [title] => example title [author1] => example author [author2] => sec ex aut [shortcontent] => cccccc [hascomments] => 1 ) [title] => title [author1] => author [author2] => aut [shortcontent] => aaaaaaaa [hascomments] => 1 ) ) ?>
Teraz robię to taką funkcją, ale nie spełnia ona tego wymogu:
<?php public function readArticlesList($category, $limitStart, $limitEnd) { $articleElement = null; $name = null; $dbObject = $this -> _dbObject; if(!$this -> _dbObject -> open($this -> _xmlFilePath.$category.'xml')) throw new XMLSectionException('Nie można odczytać bazy danych'); $this -> _dbObject -> setParserProperty(XMLReader::LOADDTD, true); while($dbObject -> read()) { if($dbObject -> nodeType == XMLReader::ELEMENT && $dbObject -> localName == 'article') $articleElement = $dbObject -> localName.$dbObject -> getAttribute('id'); if($dbObject -> nodeType == XMLReader::ELEMENT) $name = ($dbObject -> hasAttributes) ? $dbObject -> localName.$dbObject -> getAttribute('id') : $dbObject -> localName; if($dbObject -> nodeType == XMLReader::TEXT || $dbObject -> nodeType == XMLReader::CDATA) $array[$articleElement][$name] = $dbObject -> value; } return $this -> _articleArray; } ?>
Macie jakieś propozycje jak zastąpić ten fragment:
<?php if($dbObject -> nodeType == XMLReader::ELEMENT && $dbObject -> localName == 'article') $articleElement = $dbObject -> localName.$dbObject -> getAttribute('id'); ?>
tak, żebym nie musiał sprawdzać localName i getAttribute? W simplexml jest coś takiego jak children(), która sprawdza, czy węzeł ma dzieci, natomiast używając xmlreadera nie bardzo mam pomysł jak to emulować. Coś takiego jest w ogóle możliwe używając klasy xmlreader, czy jestem skazany na pisanie "na sztywno"?