Example #1
1
function xml2assoc($xml)
{
    $tree = null;
    while ($xml->read()) {
        switch ($xml->nodeType) {
            case XMLReader::END_ELEMENT:
                return $tree;
            case XMLReader::ELEMENT:
                $node = array('tag' => $xml->name, 'value' => $xml->isEmptyElement ? '' : xml2assoc($xml));
                if ($xml->hasAttributes) {
                    while ($xml->moveToNextAttribute()) {
                        $node['attributes'][$xml->name] = $xml->value;
                    }
                }
                $tree[] = $node;
                break;
            case XMLReader::TEXT:
            case XMLReader::CDATA:
                $tree .= $xml->value;
        }
    }
    return $tree;
}
Example #2
0
function xml2assoc($xml)
{
    $assoc = null;
    while ($xml->read()) {
        switch ($xml->nodeType) {
            case XMLReader::END_ELEMENT:
                return $assoc;
            case XMLReader::ELEMENT:
                $assoc[$xml->name][] = array('value' => $xml->isEmptyElement ? '' : xml2assoc($xml));
                if ($xml->hasAttributes) {
                    $el =& $assoc[$xml->name][count($assoc[$xml->name]) - 1];
                    while ($xml->moveToNextAttribute()) {
                        $el['attributes'][$xml->name] = $xml->value;
                    }
                }
                break;
            case XMLReader::TEXT:
            case XMLReader::CDATA:
                $assoc .= $xml->value;
        }
    }
    return $assoc;
}
function xml2assoc($xml)
{
    global $useragents;
    global $i;
    $tree = null;
    while ($xml->read()) {
        switch ($xml->nodeType) {
            case XMLReader::END_ELEMENT:
                return $tree;
            case XMLReader::ELEMENT:
                $node = array('tag' => $xml->name, 'value' => $xml->isEmptyElement ? '' : xml2assoc($xml));
                if ($xml->hasAttributes) {
                    while ($xml->moveToNextAttribute()) {
                        $node['attributes'][$xml->name] = $xml->value;
                        if ($xml->name == "description") {
                            $description = $xml->value;
                        }
                        if ($xml->name == "useragent") {
                            $useragent = $xml->value;
                            $useragents[$i]['description'] = $description;
                            $useragents[$i]['useragent'] = $useragent;
                            $i++;
                        }
                    }
                }
                $tree[] = $node;
                break;
            case XMLReader::TEXT:
            case XMLReader::CDATA:
                $tree .= $xml->value;
        }
    }
    return $tree;
}
Example #4
0
 private function _openml_run_evaluate()
 {
     // check uploaded file
     $description = isset($_FILES['description']) ? $_FILES['description'] : false;
     if (!check_uploaded_file($description)) {
         $this->_returnError(422);
         return;
     }
     // validate xml
     if (validateXml($description['tmp_name'], xsd('openml.run.evaluate'), $xmlErrors) == false) {
         $this->_returnError(423, $this->openmlGeneralErrorCode, $xmlErrors);
         return;
     }
     // fetch xml
     $xml = simplexml_load_file($description['tmp_name']);
     if ($xml === false) {
         $this->_returnError(424);
         return;
     }
     $run_id = (string) $xml->children('oml', true)->{'run_id'};
     $runRecord = $this->Run->getById($run_id);
     if ($runRecord == false) {
         $this->_returnError(425);
         return;
     }
     if ($runRecord->processed != null) {
         $this->_returnError(426);
         return;
     }
     $data = array('processed' => now());
     if (isset($xml->children('oml', true)->{'error'})) {
         $data['error'] = '' . $xml->children('oml', true)->{'error'};
     }
     $this->Run->update($run_id, $data);
     $implementation_ids = $this->Implementation->getAssociativeArray('fullName', 'id', '`name` = `name`');
     $this->db->trans_start();
     foreach ($xml->children('oml', true)->{'evaluation'} as $e) {
         $evaluation = xml2assoc($e, true);
         // naming convention
         $evaluation['function'] = $evaluation['name'];
         unset($evaluation['name']);
         // more naming convention
         if (array_key_exists($evaluation['implementation'], $implementation_ids)) {
             $evaluation['implementation_id'] = $implementation_ids[$evaluation['implementation']];
             unset($evaluation['implementation']);
         } else {
             $this->Log->mapping(__FILE__, __LINE__, 'Implementation ' . $evaluation['implementation'] . ' not found in database. ');
             continue;
         }
         // adding rid
         $evaluation['source'] = $run_id;
         if (array_key_exists('fold', $evaluation) && array_key_exists('repeat', $evaluation) && array_key_exists('sample', $evaluation)) {
             // evaluation_sample
             $this->Evaluation_sample->insert($evaluation);
         } elseif (array_key_exists('fold', $evaluation) && array_key_exists('repeat', $evaluation)) {
             // evaluation_fold
             $this->Evaluation_fold->insert($evaluation);
         } elseif (array_key_exists('interval_start', $evaluation) && array_key_exists('interval_end', $evaluation)) {
             // evaluation_interval
             $this->Evaluation_interval->insert($evaluation);
         } else {
             // global
             $this->Evaluation->insert($evaluation);
         }
     }
     $this->db->trans_complete();
     // update elastic search index.
     $this->elasticsearch->index('run', $run_id);
     $this->_xmlContents('run-evaluate', array('run_id' => $run_id));
 }
function schema2assoc(\XMLReader $xr, $path, \XMLWriter &$xw, $target = null)
{
    global $nss, $nss_replacements, $imports;
    $target = $xr->getAttribute("targetNamespace");
    $imports[$path] = $target;
    while ($xr->moveToNextAttribute()) {
        // записываем информацию о пространствах имен указанных в схеме префиксов
        if ($xr->prefix == "xmlns") {
            $nss[$target][$xr->localName] = replace_ns($xr->value);
        }
    }
    return xml2assoc($xr, $path, $xw, $target);
}
Example #6
0
 function xml2assoc($xml, $name)
 {
     // print "<ul>";
     $tree = null;
     print "I'm inside " . $name . "<br>";
     while ($xml->read()) {
         if ($xml->nodeType == XMLReader::END_ELEMENT) {
             print "</ul>";
             return $tree;
         } else {
             if ($xml->nodeType == XMLReader::ELEMENT) {
                 $node = array();
                 print "Adding " . $xml->name . "<br>";
                 $node['tag'] = $xml->name;
                 if ($xml->hasAttributes) {
                     $attributes = array();
                     while ($xml->moveToNextAttribute()) {
                         print "Adding attr " . $xml->name . " = " . $xml->value . "<br>";
                         $attributes[$xml->name] = $xml->value;
                     }
                     $node['attr'] = $attributes;
                 }
                 if (!$xml->isEmptyElement) {
                     $childs = xml2assoc($xml, $node['tag']);
                     $node['childs'] = $childs;
                 }
                 print $node['tag'] . " added <br>";
                 $tree[] = $node;
             } else {
                 if ($xml->nodeType == XMLReader::TEXT) {
                     $node = array();
                     $node['text'] = $xml->value;
                     $tree[] = $node;
                     print "text added = " . $node['text'] . "<br>";
                 }
             }
         }
     }
     print "returning " . count($tree) . " childs<br>";
     print "</ul>";
     return $tree;
 }