/** * Récupérer toutes les informations dans un fichier DocBook. * @param string $filename nom du fichier à analyser * @return boolean booléen indiquant si le document XML a pu être lu * @throws PEAR_ErrorStack */ function setFromDocbook($filename) { $xmltree = new XML_Tree($filename); $xmltree->setErrorHandling(PEAR_ERROR_CALLBACK, array(&$this, '_XMLTreeErrorHandler')); $article = $xmltree->getTreeFromFile(); if ($this->errors->hasErrors('error')) { return false; } $this->charset = xml_parser_get_option($xmltree->parser, XML_OPTION_TARGET_ENCODING); $this->repertoire = $this->stringValue(@$article->getAttribute("id")); $this->type = $this->stringValue(@$article->getAttribute("role")); $this->lang = $this->stringValue(@$article->getAttribute("lang")); $artinfonode = $this->getElementsByTagName($article, "articleinfo"); if (count($artinfonode) == 0) { $this->errors->push(OW_MISSING_NODE, 'error', array('file' => $filename, 'node' => 'articleinfo')); return false; } /* Traitement particulier pour les balises <author> */ $auteurs = array(); foreach ($this->getElementsByTagName($artinfonode[0], "author") as $author) { $firstnames = $this->getElementsByTagName($author, "firstname"); $surnames = $this->getElementsByTagName($author, "surname"); $nom = $this->stringValue(ucfirst(implode(' ', $firstnames)) . ' ' . ucfirst(implode(' ', $surnames))); if (preg_match('/^\\s*$/', $nom) != 0) { $auteurs[] = $nom; } } $this->auteurs = implode(', ', $auteurs); /* Traitement des autres méta-données */ $this->classement = array(); /** * Tableau des balises que l'on récupère sans traitement particulier */ $autotags = array('title', 'titleabbrev', 'pubdate', 'date', 'abstract'); foreach ($artinfonode[0]->children as $child) { $name = $child->name; if (in_array($name, $autotags)) { $this->{$name} = $this->stringValue($child); } if ($name == 'subjectset') { foreach ($this->getElementsByTagName($child, 'subject') as $subjnode) { $attribute = $this->stringValue($subjnode->getAttribute('role')); if (empty($attribute)) { continue; } $this->classement[$attribute] = array(); foreach ($this->getElementsByTagName($subjnode, 'subjectterm') as $entry) { $this->classement[$attribute][] = $this->stringValue($entry); } } } } return true; }