示例#1
0
function load_svg($filename)
{
    $tree = new XML_Tree($filename);
    $root = $tree->getTreeFromFile();
    if (!$root) {
        die("Couldn't parse svg data.");
    }
    return $root;
}
示例#2
0
 /**
  * Load the storage container
  *
  * @param   array  array containing the configuration.
  * @param string  name of the container that should be used
  * @return bool true on success or false on failure
  *
  * @access public
  */
 function init(&$conf, $containerName)
 {
     parent::init($conf, $containerName);
     if (!is_file($this->file)) {
         if (!is_file(getenv('DOCUMENT_ROOT') . $this->file)) {
             $this->stack->push(LIVEUSER_ERROR_MISSING_DEPS, 'exception', array(), "Perm initialisation failed. Can't find xml file.");
             return false;
         }
         $this->file = getenv('DOCUMENT_ROOT') . $this->file;
     }
     $tree = new XML_Tree($this->file);
     $err =& $tree->getTreeFromFile();
     if (PEAR::isError($err)) {
         $this->stack->push(LIVEUSER_ERROR, 'exception', array(), "Perm initialisation failed. Can't get tree from file");
         return false;
     }
     $this->tree =& $tree;
     if (!is_a($this->tree, 'xml_tree')) {
         $this->stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'storage layer configuration missing'));
         return false;
     }
     return true;
 }
示例#3
0
文件: XML.php 项目: Zunair/xataface
 /**
  * Load the storage container
  *
  * @param  mixed &$conf   Name of array containing the configuration.
  * @param string $containerName name of the container that should be used
  * @return  boolean true on success or false on failure
  *
  * @access  public
  */
 function init(&$conf, $containerName)
 {
     parent::init($conf, $containerName);
     if (is_array($conf['storage'])) {
         if (!is_file($this->file)) {
             if (!is_file(getenv('DOCUMENT_ROOT') . $this->file)) {
                 $this->_stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => "Auth initialisation failed. Can't find xml file."));
                 return false;
             }
             $this->file = getenv('DOCUMENT_ROOT') . $this->file;
         }
         if ($this->file) {
             if (class_exists('XML_Tree')) {
                 $tree = new XML_Tree($this->file);
                 $err =& $tree->getTreeFromFile();
                 if (PEAR::isError($err)) {
                     $this->_stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'could not connect: ' . $err->getMessage()));
                     return false;
                 }
                 $this->tree = $tree;
             } else {
                 $this->_stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => "Auth initialisation failed. Can't find XML_Tree class."));
                 return false;
             }
         } else {
             $this->_stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => "Auth initialisation failed. Can't find xml file."));
             return false;
         }
     }
     return true;
 }
示例#4
0
function update_shopinfo_xml()
{
    global $spalten;
    if (!file_exists(DIR_FS_SHOPINFO_XML) || filesize(DIR_FS_SHOPINFO_XML) == 0) {
        echo '<p class="ok">OK, die Shopdatei wurde noch nicht angelegt und muss folglich auch nicht angepasst werden.</p>' . "\n";
        return true;
    }
    echo '<p>Lade Shopdatei: <code>' . DIR_FS_SHOPINFO_XML . '</code>' . "\n";
    $tree = new XML_Tree(DIR_FS_SHOPINFO_XML, '1.0" encoding="ISO-8859-1');
    #$tree->useCdataSections();
    $root =& $tree->getTreeFromFile();
    if (PEAR::isError($root)) {
        echo '<p class="error">Fehler beim Parsen der Shopdatei:<br>' . "\n";
        echo $root->toString() . "</p>\n";
        return false;
    }
    $name_parts = explode(':', $root->name);
    if (sizeof($name_parts) > 1) {
        $namespace = $name_parts[0] . ':';
    } else {
        $namespace = '';
    }
    $requests =& $tree->getNodeAt($namespace . 'Shop/Requests');
    if (PEAR::isError($requests)) {
        #echo '<p>Warnung: Zugriff auf Produktdaten in der Shopdatei nicht gefunden.</p>'."\n";
        // Request-Tag nach dem Url-Tag einfügen
        $pos = -1;
        for ($i = 0; $i < count($root->children); ++$i) {
            if ($root->children[$i]->name == 'Url') {
                $pos = $i + 1;
            }
        }
        $requests = new XML_Tree_Node('Requests');
        $res =& $root->insertChild(null, $pos, $requests);
        if (PEAR::isError($res)) {
            echo '<p class="error">Das Requests-Tag konnte nicht in die shopinfo.xml eingef&uuml;gt werden:<br>' . "\n";
            echo $res->toString() . "</p>\n";
            return false;
        }
    }
    $offlineRequest =& $tree->getNodeAt($namespace . 'Shop/Requests/OfflineRequest');
    if (PEAR::isError($offlineRequest)) {
        #echo '<p>Warnung: Produktdatei-Angaben in der Shopdatei nicht gefunden.</p>'."\n";
        $offlineRequest =& offlineRequest($requests);
        echo '<p class="ok">OK, Produktdatei-Angaben erg&auml;nzt.</p>' . "\n";
    } else {
        $header =& $tree->getNodeAt($namespace . 'Shop/Requests/OfflineRequest/Format/Tabular/CSV/Header');
        if (PEAR::isError($header)) {
            echo '<p class="error">Das Kopfzeilen-Tag in der Shopdatei nicht gefunden:<br>' . "\n";
            echo $header->toString() . "</p>\n";
            return false;
        }
        $old_titel = $header->content;
        // Funktion getContent gibt es nicht.
        #echo 'old_titel: '.htmlspecialchars($old_titel)."\n\n";
        $corrected = false;
        if ($header->getAttribute('columns') != count($spalten)) {
            $header->setAttribute('columns', count($spalten));
            $corrected = true;
        }
        $mappings =& $tree->getNodeAt($namespace . 'Shop/Requests/OfflineRequest/Format/Tabular/Mappings');
        if (PEAR::isError($mappings)) {
            echo '<p class="error">Das Mappings-Tag in der Shopdatei nicht gefunden:<br>' . "\n";
            echo $mappings->toString() . "</p>\n";
            return false;
        }
        foreach ($mappings->children as $idx => $child) {
            if (count($child->attributes) > 0) {
                if ($child->getAttribute('columnName') != $spalten[$child->getAttribute('column') - 1]) {
                    #echo $idx.': '.$child->getAttribute('columnName').' =&gt; ';
                    $mappings->children[$idx]->setAttribute('columnName', $spalten[$child->getAttribute('column') - 1]);
                    #echo $mappings->children[$idx]->getAttribute('columnName')."<br>\n";
                    $corrected = true;
                }
            }
        }
        if (defined('DEFAULT_QUOTE')) {
            $titel = DEFAULT_QUOTE . implode(DEFAULT_QUOTE . DEFAULT_DELIMITER . DEFAULT_QUOTE, $spalten) . DEFAULT_QUOTE;
        } else {
            $titel = implode(DEFAULT_DELIMITER, $spalten);
        }
        #echo 'titel: '.htmlspecialchars($titel)."\n\n";
        if ($old_titel != $titel) {
            $header->setContent($titel);
        }
        $special =& $tree->getNodeAt($namespace . 'Shop/Requests/OfflineRequest/Format/Tabular/CSV/SpecialCharacters');
        if (PEAR::isError($special)) {
            echo '<p class="error">Das Sonderzeichen-Tag in der Shopdatei nicht gefunden:<br>' . "\n";
            echo $special->toString() . "</p>\n";
            return false;
        }
        $old_escape = $special->getAttribute('escaped');
        $old_quote = $special->getAttribute('quoted');
        $old_lineend = $special->getAttribute('lineend');
        $old_delimiter = $special->getAttribute('delimiter');
        if (defined('DEFAULT_ESCAPE')) {
            $special->setAttribute('escaped', DEFAULT_ESCAPE);
        } else {
            $special->unsetAttribute('escaped');
        }
        if (defined('DEFAULT_QUOTE')) {
            $special->setAttribute('quoted', DEFAULT_QUOTE);
        } else {
            $special->unsetAttribute('quoted');
        }
        if (defined('DEFAULT_LINEEND')) {
            $special->setAttribute('lineend', DEFAULT_LINEEND == "\n" ? '\\n' : (DEFAULT_LINEEND == "\r" ? '\\r' : '\\r\\n'));
        } else {
            $special->unsetAttribute('lineend');
        }
        if (defined('DEFAULT_DELIMITER')) {
            $special->setAttribute('delimiter', DEFAULT_DELIMITER == "\t" ? '[tab]' : DEFAULT_DELIMITER);
        } else {
            $special->unsetAttribute('delimiter');
        }
        $new_escape = $special->getAttribute('escaped');
        $new_quote = $special->getAttribute('quoted');
        $new_lineend = $special->getAttribute('lineend');
        $new_delimiter = $special->getAttribute('delimiter');
        if (!$corrected && $old_titel == $titel && $new_escape == $old_escape && $new_quote == $old_quote && $new_lineend == $old_lineend && $new_delimiter == $old_delimiter) {
            echo '<p class="ok">OK, die Shopdatei wurde bereits aktualisiert.</p>' . "\n";
            return true;
        }
        if ($old_titel != $titel) {
            echo '<p class="ok">OK, Kopfzeile aktualisiert.</p>' . "\n";
        }
        if ($corrected) {
            echo '<p class="ok">OK, Spaltennamen aktualisiert.</p>' . "\n";
        }
        if ($new_escape != $old_escape) {
            echo '<p class="ok">OK, Escape-Zeichen aktualisiert.</p>' . "\n";
        }
        if ($new_quote != $old_quote) {
            echo '<p class="ok">OK, Zeichenkettenbegrenzer aktualisiert.</p>' . "\n";
        }
        if ($new_lineend != $old_lineend) {
            echo '<p class="ok">OK, Zeilenendezeichen aktualisiert.</p>' . "\n";
        }
        if ($new_delimiter != $old_delimiter) {
            echo '<p class="ok">OK, Trennzeichenzeichen aktualisiert.</p>' . "\n";
        }
    }
    #echo '<pre>'.(htmlspecialchars($tree->get())).'</pre>'."\n";
    if (!is_writable(DIR_FS_SHOPINFO_XML)) {
        echo '<p class="error">Die Shopdatei kann nicht geschrieben werden:<br>' . DIR_FS_SHOPINFO_XML . "</p>\n";
        return false;
    }
    if (!($handle = @fopen(DIR_FS_SHOPINFO_XML, 'wb'))) {
        echo '<p class="error">Die Shopdatei kann nicht zum Schreiben ge&ouml;ffnet werden:<br>' . DIR_FS_SHOPINFO_XML . "</p>\n";
        return false;
    }
    flock($handle, LOCK_EX);
    if (!@fwrite($handle, $tree->get())) {
        echo '<p class="error">Fehler beim Schreiben der Shopdatei:<br>' . DIR_FS_SHOPINFO_XML . "</p>\n";
        return false;
    }
    flock($handle, LOCK_UN);
    @fclose($handle);
    // wenn hier etwas schief geht, ignorieren
    #$tree->free();
    echo '<p class="ok">OK, die Shopdatei wurde aktualisiert.<br>' . DIR_FS_SHOPINFO_XML . '</p>' . "\n";
    return true;
}
/**
 * Récupérer toutes les informations dans un fichier DocBook.
 * @param string $filename nom du fichier à analyser
 * @return object DocInfos objet contenant les infos de l'article, ou un tableau de chaînes contenant des messages d'erreurs
 * @todo Relire le code, il ne vérifie parfois pas assez les données d'entrées/les erreurs qui peuvent survenir pendant le traitement.
 */
function docbookGetArticleInfoFromFile($filename)
{
    $doc = new DocInfos();
    /* Extrait du XML toutes les informations pour remplir la classe Article */
    /* Obtenir un arbre à partir du fichier XML */
    $xmltree = new XML_Tree($filename);
    /* lecture du fichier qui récupère la balise <article> */
    $article = $xmltree->getTreeFromFile();
    if ($xmltree->isError($article)) {
        $erreur = $article->getUserInfo();
        if ($erreur == '') {
            $erreur = 'probablement un document mal formé';
        }
        return array('Impossible de parser le fichier XML (' . $erreur . ')');
    }
    preg_match('/^\\s*<\\?xml(.*?)encoding="(.+?)"/', file_get_contents($filename), $charset);
    $charset = $charset[2];
    $doc->repertoire = _toUtf8($charset, trim($article->getAttribute("id")));
    $doc->type = _toUtf8($charset, array_key_exists("role", $article->attributes) ? $article->getAttribute("role") : "article");
    $doc->lang = _toUtf8($charset, array_key_exists("lang", $article->attributes) ? $article->getAttribute("lang") : "fr");
    $artinfonode = getElementsByTagName($article, "articleinfo");
    if (count($artinfonode) == 0) {
        return array('Impossible de continuer à parser le fichier XML : il manque la section articleinfo du docbook');
    }
    /* Traitement particulier pour les balises <author> */
    $auteurs = array();
    foreach (getElementsByTagName($artinfonode[0], "author") as $author) {
        $firstnames = getElementsByTagName($author, "firstname");
        $surnames = getElementsByTagName($author, "surname");
        $auteurs[] = (count($firstnames) ? ucfirst(trim(tree2text($firstnames[0]))) : "") . ' ' . (count($surnames) ? ucfirst(trim(tree2text($surnames[0]))) : "");
    }
    $doc->auteurs = _toUtf8($charset, implode(', ', $auteurs));
    $doc->classement = array();
    foreach ($artinfonode[0]->children as $child) {
        /* Récupération des balises <title>, <pubdate> et <date> */
        if (!strcmp($child->name, "title")) {
            $doc->titre = _toUtf8($charset, tree2text($child));
        }
        if (!strcmp($child->name, "titleabbrev")) {
            $doc->titremini = _toUtf8($charset, tree2text($child));
        }
        if (!strcmp($child->name, "pubdate")) {
            $doc->pubdate = _toUtf8($charset, tree2text($child));
        }
        if (!strcmp($child->name, "date")) {
            $doc->update = _toUtf8($charset, tree2text($child));
        }
        if (!strcmp($child->name, "subjectset")) {
            foreach (getElementsByTagName($child, "subject") as $subjnode) {
                $attribute = _toUtf8($charset, $subjnode->getAttribute("role"));
                $doc->classement[$attribute] = array();
                foreach (getElementsByTagName($subjnode, "subjectterm") as $entry) {
                    $doc->classement[$attribute][] = _toUtf8($charset, tree2text($entry));
                }
            }
        }
        if (!strcmp($child->name, "abstract")) {
            $doc->accroche = _toUtf8($charset, tree2text($child));
        }
    }
    return $doc;
}
 /**
  * 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;
 }
/**
*
* @param string	$file	the file to run through
*
* @return boolean
* @access public
*/
function process_errors_file($path, $file)
{
    bam('ERRORS ' . $file);
    $xml_object = new XML_Tree($file);
    $root = $xml_object->getTreeFromFile();
    assert_equals($root->name, 'files');
    echo $locale = $root->attributes['locale'];
    for (reset($root->children); null !== ($file_index = key($root->children)); next($root->children)) {
        $file_tag =& $root->children[$file_index];
        $file_name = $path . '/' . $file_tag->attributes['source'] . '/' . $locale . '/lang_errors.xml';
        // now create the file (and directory if required)
        create_directory($path . '/' . $file_tag->attributes['source'] . '/' . $locale);
        string_to_file($file_tag->children[0]->get(), $file_name);
    }
    return true;
}
<?php

require_once 'XML/Tree.php';
$xmlfile = 'presentations/slides/sdphp/data/sdphp_talk2.xml';
$tree = new XML_Tree($xmlfile);
$root = $tree->getTreeFromFile();
echo "<pre>\n";
print_r($root);
echo "</pre>\n";
示例#9
0
文件: XML.php 项目: Zunair/xataface
 /**
  *
  *
  *
  * @param array &$storageConf Array with the storage configuration
  * @return boolean true on success, false on failure.
  *
  * @access public
  */
 function init(&$storageConf)
 {
     if (!parent::init($storageConf)) {
         return false;
     }
     if (!is_file($this->file)) {
         if (!is_file(getenv('DOCUMENT_ROOT') . $this->file)) {
             $this->_stack->push(LIVEUSER_ERROR_MISSING_DEPS, 'exception', array(), "Perm initialisation failed. Can't find xml file.");
             return false;
         }
         $this->file = getenv('DOCUMENT_ROOT') . $this->file;
     }
     if (!class_exists('XML_Tree')) {
         $this->_stack->push(LIVEUSER_ERROR_MISSING_DEPS, 'exception', array(), "Perm initialisation failed. Can't find XML_Tree class");
         return false;
     }
     $tree = new XML_Tree($this->file);
     $err =& $tree->getTreeFromFile();
     if (PEAR::isError($err)) {
         $this->_stack->push(LIVEUSER_ERROR, 'exception', array(), "Perm initialisation failed. Can't get tree from file");
         return false;
     }
     $this->tree = $tree;
     return true;
 }