Esempio n. 1
0
 /**
  * @param Result $result
  */
 public function output(Result $result)
 {
     $assumptions = $result->getAssumptions();
     foreach ($assumptions as $assumption) {
         $fileElements = $this->xpath->query('/phpa/files/file[@name="' . $assumption['file'] . '"]');
         if ($fileElements->length === 0) {
             $files = $this->xpath->query('/phpa/files')->item(0);
             $fileElement = $this->document->createElement('file');
             $fileElement->setAttribute('name', $assumption['file']);
             $files->appendChild($fileElement);
         } else {
             $fileElement = $fileElements->item(0);
         }
         $lineElement = $this->document->createElement('line');
         $lineElement->setAttribute('number', $assumption['line']);
         $lineElement->setAttribute('message', $assumption['message']);
         $fileElement->appendChild($lineElement);
     }
     $this->document->documentElement->setAttribute('assumptions', $result->getAssumptionsCount());
     $this->document->documentElement->setAttribute('bool-expressions', $result->getBoolExpressionsCount());
     $this->document->documentElement->setAttribute('percentage', $result->getPercentage());
     $this->document->preserveWhiteSpace = false;
     $this->document->formatOutput = true;
     $this->document->save($this->file);
     $this->cli->out(sprintf('Written %d assumption(s) to file %s', $result->getAssumptionsCount(), $this->file));
 }
Esempio n. 2
0
 /**
  * Save FB2 file
  * @param string $path
  */
 public function save($path = '')
 {
     if ($this->fictionBook instanceof FictionBook) {
         self::$FB2DOM = new \DOMDocument("1.0", "UTF-8");
         self::$FB2DOM->preserveWhiteSpace = FALSE;
         self::$FB2DOM->formatOutput = TRUE;
         $this->fictionBook->buildXML();
         self::$FB2DOM->schemaValidate("./XSD/FB2.2/FictionBook.xsd");
         //$domDoc->schemaValidate("./XSD/FB2.0/FictionBook2.xsd");
         self::$FB2DOM->save($path);
         echo self::$FB2DOM->saveXML();
     }
 }
Esempio n. 3
0
 private function createXML()
 {
     global $Site;
     global $dbPages;
     global $dbPosts;
     global $Url;
     $doc = new DOMDocument('1.0', 'UTF-8');
     // Friendly XML code
     $doc->formatOutput = true;
     // Create urlset element
     $urlset = $doc->createElement('urlset');
     $attribute = $doc->createAttribute('xmlns');
     $attribute->value = 'http://www.sitemaps.org/schemas/sitemap/0.9';
     $urlset->appendChild($attribute);
     // --- Base URL ---
     // Create url, loc and lastmod elements
     $url = $doc->createElement('url');
     $loc = $doc->createElement('loc', $Site->url());
     $lastmod = $doc->createElement('lastmod', '');
     // Append loc and lastmod -> url
     $url->appendChild($loc);
     $url->appendChild($lastmod);
     // Append url -> urlset
     $urlset->appendChild($url);
     // --- Pages and Posts ---
     $all = array();
     $url = trim($Site->url(), '/');
     // --- Pages ---
     $filter = trim($Url->filters('page'), '/');
     $pages = $dbPages->getDB();
     unset($pages['error']);
     foreach ($pages as $key => $db) {
         $permalink = empty($filter) ? $url . '/' . $key : $url . '/' . $filter . '/' . $key;
         $date = Date::format($db['date'], DB_DATE_FORMAT, SITEMAP_DATE_FORMAT);
         array_push($all, array('permalink' => $permalink, 'date' => $date));
     }
     // --- Posts ---
     $filter = rtrim($Url->filters('post'), '/');
     $posts = $dbPosts->getDB();
     foreach ($posts as $key => $db) {
         $permalink = empty($filter) ? $url . '/' . $key : $url . '/' . $filter . '/' . $key;
         $date = Date::format($db['date'], DB_DATE_FORMAT, SITEMAP_DATE_FORMAT);
         array_push($all, array('permalink' => $permalink, 'date' => $date));
     }
     // Generate the XML for posts and pages
     foreach ($all as $db) {
         // Create url, loc and lastmod elements
         $url = $doc->createElement('url');
         $loc = $doc->createElement('loc', $db['permalink']);
         $lastmod = $doc->createElement('lastmod', $db['date']);
         // Append loc and lastmod -> url
         $url->appendChild($loc);
         $url->appendChild($lastmod);
         // Append url -> urlset
         $urlset->appendChild($url);
     }
     // Append urlset -> XML
     $doc->appendChild($urlset);
     $doc->save(PATH_PLUGINS_DATABASES . $this->directoryName . DS . 'sitemap.xml');
 }
Esempio n. 4
0
function saveanswer($filename, $objectid, $answer, $userid)
{
    if (!file_exists($filename)) {
        file_put_contents($filename, "<?xml version=\"1.0\" ?>\n<responses></responses>");
    }
    libxml_use_internal_errors(true);
    $doc = new DOMDocument();
    $result = $doc->load($filename);
    if (!$result) {
        $message = "";
        foreach (libxml_get_errors() as $error) {
            $message .= $error->message;
            ///$and = "\nand ";
        }
        libxml_clear_errors();
        echo json_encode(array(status => 0, message => "Could not parse data file! Reason: {$message}"));
        exit;
    }
    //$xpath = new DOMXPath($doc);
    $responsenode = $doc->documentElement->appendChild($doc->createElement("response"));
    $responsenode->setAttribute("objectid", $objectid);
    $responsenode->setAttribute("answer", $answer);
    $responsenode->setAttribute("userid", $userid);
    $doc->save($filename);
    echo json_encode(array(status => 1));
}
Esempio n. 5
0
 private function createXML()
 {
     global $Site;
     global $dbPages;
     global $dbPosts;
     global $Url;
     $xml = '<?xml version="1.0" encoding="UTF-8" ?>';
     $xml .= '<rss version="2.0">';
     $xml .= '<channel>';
     $xml .= '<title>' . $Site->title() . '</title>';
     $xml .= '<link>' . $Site->url() . '</link>';
     $xml .= '<description>' . $Site->description() . '</description>';
     $posts = buildPostsForPage(0, 10, true);
     foreach ($posts as $Post) {
         $xml .= '<item>';
         $xml .= '<title>' . $Post->title() . '</title>';
         $xml .= '<link>' . $Post->permalink(true) . '</link>';
         $xml .= '<description>' . $Post->description() . '</description>';
         $xml .= '</item>';
     }
     $xml .= '</channel></rss>';
     // New DOM document
     $doc = new DOMDocument();
     // Friendly XML code
     $doc->formatOutput = true;
     $doc->loadXML($xml);
     $doc->save(PATH_PLUGINS_DATABASES . $this->directoryName . DS . 'rss.xml');
 }
Esempio n. 6
0
 public function __construct($config)
 {
     $this->_config = $config;
     // Create XML file if not exist
     $filePath = $this->getPath();
     if (!file_exists($filePath)) {
         $arr = explode('/', dirname($filePath));
         $curr = array();
         foreach ($arr as $val) {
             $curr[] = $val;
             $path = implode('/', $curr) . '/';
             if (!file_exists($path)) {
                 mkdir($path, 0777);
                 @chmod($path, 0777);
             }
         }
         $xml = new \DOMDocument();
         $error = $xml->createElement("errors");
         $xml->appendChild($error);
         $xml->formatOutput = true;
         $xml->save($filePath);
         @chmod($filePath, 0777);
     }
     $this->_xml = simplexml_load_file($filePath);
 }
Esempio n. 7
0
 public function run()
 {
     foreach ($this->datasource as $concursoName => $concurso) {
         $xml = new \SimpleXMLElement('<concursos/>');
         foreach ($this->data[$concursoName] as $nrconcurso => $concursoData) {
             $concursoXml = $xml->addChild('concurso');
             $concursoXml->addAttribute('numero', $nrconcurso);
             $concursoXml->addChild('data', $concursoData['data']);
             $dezenas = $concursoXml->addChild('dezenas');
             foreach ($concursoData['dezenas'] as $dezena) {
                 $dezenas->addChild('dezena', $dezena);
             }
             $faixasPremios = $concursoXml->addChild('faixas_premios');
             foreach ($concursoData['faixas_premios'] as $faixa) {
                 $faixasPremios->addChild('faixa', $faixa);
             }
             $concursoXml->addChild('arrecadacao', $concursoData['arrecadacao']);
             $concursoXml->addChild('total_ganhadores', $concursoData['total_ganhadores']);
             $concursoXml->addChild('acumulado', $concursoData['acumulado']);
             $concursoXml->addChild('valor_acumulado', $concursoData['valor_acumulado']);
         }
         $filename = $this->localstorage . $concurso['xml'];
         $dom = new \DOMDocument('1.0');
         $dom->preserveWhiteSpace = false;
         $dom->formatOutput = true;
         $dom->loadXML($xml->asXML());
         $dom->save($filename);
     }
 }
Esempio n. 8
0
function cascadenik_svg_compile($file, $path=null) {
  global $tmp_dir;

  if(!preg_match("/^(.*\/)([^\/]*)$/", $file, $m)) {
    print "Mapnik Rotate: No path found???\n";
    return;
  }
  if(!$path)
    $path=$m[1];
  $nfile="$tmp_dir/$m[2]";

  $dom=new DOMDocument();
  $dom->load($file);

  $list=$dom->getElementsByTagName("Stylesheet");
  for($i=0; $i<$list->length; $i++) {
    $mss_file=$list->item($i)->getAttribute("src");
    cascadenik_svg_process($mss_file, $mss_file, $path);
    $list->item($i)->setAttribute("src", "$tmp_dir/$mss_file");
  }

  $dom->save($nfile);

  $file=$nfile;
}
Esempio n. 9
0
function combineXML($dir, $id)
{
    $dir .= DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'vqmod' . DIRECTORY_SEPARATOR . 'xml';
    $files = is_dir($dir) ? glob($dir . DIRECTORY_SEPARATOR . '*.xml', GLOB_BRACE) : array();
    if (empty($files)) {
        return;
    }
    $modification = <<<XML
<modification>
\t<id>{$id}</id>
\t<version>2.1.0.2</version>
\t<vqmver>2.4.1</vqmver>
\t<author></author>
</modification>
XML;
    $xml = new DOMDocument('1.0', 'UTF-8');
    $xml->formatOutput = true;
    $xml->preserveWhiteSpace = true;
    $xml->loadXml($modification);
    $modification = $xml->getElementsByTagName('modification')->item(0);
    $author = $modification->getElementsByTagName('author')->item(0);
    foreach ($files as $file) {
        $dom = parseXML($file);
        $fileTags = $dom->getElementsByTagName('modification')->item(0)->getElementsByTagName('file');
        $originAutor = $dom->getElementsByTagName('modification')->item(0)->getElementsByTagName('author');
        $author->textContent = $originAutor->item(0)->textContent;
        for ($i = 0; $i < $fileTags->length; $i++) {
            $fileTag = $fileTags->item($i);
            $fileTag = $xml->importNode($fileTag, true);
            $modification->appendChild($fileTag);
        }
        unlink($file);
    }
    $xml->save($dir . DIRECTORY_SEPARATOR . $id . '.xml');
}
Esempio n. 10
0
function createRss()
{
    $rss_name = 'rss2.xml';
    $rss_title = "News feed";
    $rss_link = "http://lessons/xml/news.php";
    $dom = new DOMDocument('1.0', 'utf-8');
    $dom->formatOutput = true;
    // с отступами
    $dom->preserveWhiteSpace = false;
    $rss = $dom->createElement('rss');
    //    $rss->setAttribute('version', '2.0');
    $dom->appendChild($rss);
    $channel = $dom->createElement('channel');
    $rss->appendChild($channel);
    $title = $dom->createElement('title', $rss_title);
    $link = $dom->createElement('link', $rss_link);
    $channel->appendChild($title);
    $channel->appendChild($link);
    $item = $dom->createElement('item');
    $iIitle = $dom->createElement('title', 'Item title');
    $iLink = $dom->createElement('link', 'Link to item');
    $iDescription = $dom->createElement('descriptiion', 'Description of item');
    $iPubDate = $dom->createElement('pubDate', 'Publication date');
    $iCategory = $dom->createElement('category', 'News category');
    $item->appendChild($iIitle);
    $item->appendChild($iLink);
    $item->appendChild($iDescription);
    $item->appendChild($iPubDate);
    $item->appendChild($iCategory);
    $channel->appendChild($item);
    $dom->save($rss_name);
}
Esempio n. 11
0
 /**
  * Create the salt code
  * A salt code is a random set of bytes of a 
  * fixed length that is added to 
  * the input of a hash algorithm.
  */
 public static function resetSalt()
 {
     $saltpattern = self::createSalt();
     $filename = APPLICATION_PATH . "/configs/config.xml";
     if (file_exists($filename)) {
         $xml = simplexml_load_file($filename);
         if (empty($xml->config->saltpattern)) {
             $config = $xml->config;
             $config->addChild('saltpattern', $saltpattern);
         } else {
             $xml->config->saltpattern = $saltpattern;
         }
         // Get the xml string
         $xmlstring = $xml->asXML();
         // Prettify and save the xml configuration
         $dom = new DOMDocument();
         $dom->loadXML($xmlstring);
         $dom->formatOutput = true;
         $formattedXML = $dom->saveXML();
         // Save the config xml file
         if (@$dom->save(APPLICATION_PATH . "/configs/config.xml")) {
             return true;
         } else {
             throw new Exception("Error on saving the xml file in " . APPLICATION_PATH . "/configs/config.xml <br/>Please check the folder permissions");
         }
     } else {
         throw new Exception('There was a problem to save data in the config.xml file. Permission file problems?');
     }
 }
Esempio n. 12
0
function create_xml($data, $keys_array, $filename, $table_name)
{
    $names = array('categories' => 'category', 'comp_orders' => 'comp_order', 'orders' => 'order', 'products' => 'product', 'statuses' => 'status', 'users' => 'user');
    // Создаем DOM документ
    $xml = new DOMDocument('1.0', 'UTF-8');
    $xml->formatOutput = true;
    // Создаем корневой элемент
    $loft_shop = $xml->createElement("loft_shop");
    $xml->appendChild($loft_shop);
    // Создаем список
    $elements = $xml->createElement($table_name);
    $loft_shop->appendChild($elements);
    foreach ($data as $item) {
        // Создаем элемент списка
        $element = $xml->createElement($names[$table_name]);
        $id = $xml->createAttribute("id");
        $id->value = $item['id'];
        // Устанавливаем атрибут id
        $element->appendChild($id);
        for ($i = 1; $i < count($keys_array); $i++) {
            $xml_field = $xml->createElement($keys_array[$i], $item[$keys_array[$i]]);
            $element->appendChild($xml_field);
        }
        $elements->appendChild($element);
    }
    $xml->save($filename);
}
function addCustomerToIndex($customerId)
{
    $indexDoc = simplexml_load_file('customer-index.xml');
    $lastValue = $indexDoc->lastIndex;
    $lastValue = $lastValue + 1;
    $dom = new DOMDocument();
    $dom->load("customer-index.xml");
    $value = '2290000000' . $lastValue;
    $dom->getElementsByTagName('lastIndex')->item(0)->nodeValue = $lastValue;
    //update the last value
    //$doc->getElementsByTagName("title")->item(0)->nodeValue = $titleText;
    $customerElement = $dom->createElement('customer');
    //createNode($dom, $dom->customers,'customer');
    $custIdAttr = $dom->createAttribute('customer_id');
    $custIdVal = $dom->createTextNode($customerId);
    $custIdAttr->appendChild($custIdVal);
    $customerElement->appendChild($custIdAttr);
    $suIdAttr = $dom->createAttribute('cust_sid');
    $suIdVal = $dom->createTextNode($value);
    $suIdAttr->appendChild($suIdVal);
    $customerElement->appendChild($suIdAttr);
    $dom->getElementsByTagName('customers')->item(0)->appendChild($customerElement);
    $dom->save('customer-index.xml');
    return $value;
}
Esempio n. 14
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $session = $this->get('phpcr.session');
     $file = $input->getArgument('file');
     $pretty = $input->getOption('pretty');
     $exportDocument = $input->getOption('document');
     $dialog = $this->get('helper.question');
     if (file_exists($file)) {
         $confirmed = true;
         if (false === $input->getOption('no-interaction')) {
             $confirmed = $dialog->ask($input, $output, new ConfirmationQuestion('File already exists, overwrite?'));
         }
         if (false === $confirmed) {
             return;
         }
     }
     $stream = fopen($file, 'w');
     $absPath = $input->getArgument('absPath');
     PathHelper::assertValidAbsolutePath($absPath);
     if (true === $exportDocument) {
         $session->exportDocumentView($absPath, $stream, $input->getOption('skip-binary'), $input->getOption('no-recurse'));
     } else {
         $session->exportSystemView($absPath, $stream, $input->getOption('skip-binary'), $input->getOption('no-recurse'));
     }
     fclose($stream);
     if ($pretty) {
         $xml = new \DOMDocument(1.0);
         $xml->load($file);
         $xml->preserveWhitespace = true;
         $xml->formatOutput = true;
         $xml->save($file);
     }
 }
Esempio n. 15
0
 public function merge()
 {
     /**
     * 	7. xl/workbook.xml
     		=> add
     		<sheet name="{New sheet}" sheetId="{N}" r:id="rId{N}"/>
     */
     $filename = "{$this->result_dir}/xl/workbook.xml";
     $dom = new \DOMDocument();
     $dom->load($filename);
     $xpath = new \DOMXPath($dom);
     $xpath->registerNamespace("m", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
     $elems = $xpath->query("//m:sheets");
     foreach ($elems as $e) {
         $tag = $dom->createElement('sheet');
         $tag->setAttribute('name', $this->sheet_name);
         $tag->setAttribute('sheetId', $this->sheet_number);
         $tag->setAttribute('r:id', "rId" . $this->sheet_number);
         $e->appendChild($tag);
         break;
     }
     // make sure all worksheets have the correct rId - we might have assigned them new ids
     // in the Tasks\WorkbookRels::merge() method
     $elems = $xpath->query("//m:sheets/m:sheet");
     foreach ($elems as $e) {
         $e->setAttribute("r:id", "rId" . $e->getAttribute("sheetId"));
     }
     $dom->save($filename);
 }
Esempio n. 16
0
function create_mulitsettings()
{
    $dom = new DOMDocument('1.0', 'utf-8');
    $root = $dom->createElement('multilogin');
    $dom->appendChild($root);
    $root->appendChild($guest = $dom->createElement("guest"));
    $guest->appendChild($dom->createElement("ShowUsername", "true"));
    $guest->appendChild($dom->createElement("ShowUserOnline", "true"));
    $guest->appendChild($dom->createElement("ShowUserLastTime", "fasle"));
    $guest->appendChild($dom->createElement("ShowUserAllTime", "false"));
    $guest->appendChild($dom->createElement("ShowUserPic", "false"));
    $root->appendChild($firstNode = $dom->createElement("user"));
    $firstNode->appendChild($dom->createElement("ShowUsername", "true"));
    $firstNode->appendChild($dom->createElement("ShowUserOnline", "true"));
    $firstNode->appendChild($dom->createElement("ShowUserLastTime", "true"));
    $firstNode->appendChild($dom->createElement("ShowUserAllTime", "false"));
    $firstNode->appendChild($dom->createElement("ShowUserPic", "true"));
    $root->appendChild($secondNode = $dom->createElement("admin"));
    $secondNode->appendChild($dom->createElement("ShowUsername", "true"));
    $secondNode->appendChild($dom->createElement("ShowUserOnline", "true"));
    $secondNode->appendChild($dom->createElement("ShowUserLastTime", "true"));
    $secondNode->appendChild($dom->createElement("ShowUserAllTime", "true"));
    $secondNode->appendChild($dom->createElement("ShowUserPic", "true"));
    $dom->save('./include/Settings/multilogin.xml');
}
Esempio n. 17
0
 public function generateIndex()
 {
     // Create dom object
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->formatOutput = true;
     $dom->substituteEntities = false;
     // Create <urlset> root tag
     $sitemapindex = $dom->createElement('sitemapindex');
     // Add attribute of urlset
     $xmlns = $dom->createAttribute('xmlns');
     $sitemapindexText = $dom->createTextNode('http://www.sitemaps.org/schemas/sitemap/0.9');
     $sitemapindex->appendChild($xmlns);
     $xmlns->appendChild($sitemapindexText);
     foreach ($this->generators as $generator) {
         $sitemap = $dom->createElement('sitemap');
         $loc = $dom->createElement('loc');
         $loc->appendChild($dom->createTextNode($generator->getWebFilePath()));
         $sitemap->appendChild($loc);
         $lastmod = $dom->createElement('lastmod');
         $lastmod->appendChild($dom->createTextNode(date('Y-m-d')));
         $sitemap->appendChild($lastmod);
         $sitemapindex->appendChild($sitemap);
     }
     $dom->appendChild($sitemapindex);
     return $dom->save($this->config['file_path']);
 }
Esempio n. 18
0
 public function WriteXmlFile($XmlData, $FilePath)
 {
     $Xml = simplexml_load_string($XmlData);
     $Doc = new DOMDocument();
     $Doc->loadXML($Xml->asXML());
     $Doc->save($FilePath);
 }
Esempio n. 19
0
/**
 *添加信息到xml文件
 */
function addToXML($filename, $brand, $title, $url)
{
    //处理产品名字符乱码
    $brand = strReplaceToEntity($brand);
    $title = strReplaceToEntity($title);
    $url = strReplaceToEntity($url);
    $xml = new DOMDocument('1.0', 'utf-8');
    $xml->formatOutput = true;
    if ($xml->load($filename)) {
        $root = $xml->documentElement;
        //获得根节点(root)
        $productXml = $xml->createElement("product");
        $titleXml = $xml->createElement("title", $title);
        $brandXml = $xml->createElement("brand", $brand);
        $urlXml = $xml->createElement("url", $url);
        $productXml->appendChild($titleXml);
        $productXml->appendChild($brandXml);
        $productXml->appendChild($urlXml);
        $root->appendChild($productXml);
        $xml->appendChild($root);
        //生成XML
        $xml->save($filename);
    } else {
        echo 'xml 文件 ' . $filename . '更新错误! <br/>';
    }
}
Esempio n. 20
0
function remove_mlf_suffix($file, $languages)
{
    $xml = new DOMDocument();
    $xml->formatOutput = true;
    $xml->preserveWhiteSpace = false;
    $xml->load($file) or die("Error: Cannot create object");
    $post_types = $xml->getElementsByTagName('post_type');
    for ($i = 0; $i < $post_types->length; $i++) {
        $pt = $post_types->item($i)->nodeValue;
        foreach ($languages as $lang) {
            $pos = strpos($pt, '_t_' . $lang);
            if ($pos !== false) {
                $pt = str_replace('_t_' . $lang, '', $pt);
                break;
            }
        }
        $post_types->item($i)->nodeValue = $pt;
    }
    $guid = $xml->getElementsByTagName('guid');
    for ($i = 0; $i < $guid->length; $i++) {
        $link = $guid->item($i)->nodeValue;
        foreach ($languages as $lang) {
            $pos = strpos($link, '_t_' . $lang);
            if ($pos !== false) {
                $link = str_replace('_t_' . $lang, '', $link);
                break;
            }
        }
        $guid->item($i)->nodeValue = htmlentities($link);
    }
    $xml->save($file);
}
Esempio n. 21
0
function save_to_xml($data = null, $list, $file)
{
    $doc = new DOMDocument('1.0', 'ISO-8859-1');
    $doc->formatOutput = true;
    $r = $doc->createElement("list");
    $doc->appendChild($r);
    $category = $doc->createElement("category");
    $category->appendChild($doc->createTextNode($list));
    $r->appendChild($category);
    $lastindex = $doc->createElement("lastindex");
    $lastindex->appendChild($doc->createTextNode("0"));
    $r->appendChild($lastindex);
    if ($data != null) {
        for ($i = 0; $i < sizeof($data); $i++) {
            $b = $doc->createElement("item");
            $attr = $r->appendChild($b);
            $attr->setAttribute('id', $data[$i]['id']);
            $title = $doc->createElement("title");
            $title->appendChild($doc->createTextNode($data[$i]['title']));
            $b->appendChild($title);
            $author = $doc->createElement("author");
            $author->appendChild($doc->createTextNode($data[$i]['author']));
            $b->appendChild($author);
            $price = $doc->createElement("price");
            $price->appendChild($doc->createTextNode($data[$i]['price']));
            $b->appendChild($price);
            $rating = $doc->createElement("rating");
            $rating->appendChild($doc->createTextNode($data[$i]['rating']));
            $b->appendChild($rating);
        }
    }
    $doc->save($file);
}
Esempio n. 22
0
 public function merge()
 {
     $filename = "{$this->result_dir}/docProps/app.xml";
     $dom = new \DOMDocument();
     $dom->load($filename);
     /*
     		 * 		=> in HeadingPairs/vt:vector/vt:variant[2] set <vt:i4> to {N}
     		=> in TitlesOfParts/vt:vector set attribute 'size' to {N}
     			=> add
     				<vt:lpstr>{New sheet}</vt:lpstr>
     */
     $xpath = new \DOMXPath($dom);
     $xpath->registerNamespace("m", "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties");
     $xpath->registerNamespace("mvt", "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes");
     $elems = $xpath->query("//m:HeadingPairs/mvt:vector/mvt:variant[2]/mvt:i4");
     foreach ($elems as $e) {
         $e->nodeValue = $this->sheet_number;
     }
     $elems = $xpath->query("//m:TitlesOfParts/mvt:vector");
     foreach ($elems as $e) {
         $e->setAttribute('size', $this->sheet_number);
         $tag = $dom->createElement('vt:lpstr');
         $tag->nodeValue = $this->sheet_name;
         $e->appendChild($tag);
     }
     $dom->save($filename);
 }
Esempio n. 23
0
 /**
 * Save the setup data
 * @param array $dbconfig
 * @param array $preferences
 * 
 * <?xml version="1.0" encoding="UTF-8"?>
 		<shineisp>
 			<config>
 				<database>
 					<hostname>localhost</hostname>
 					<db>shineisp</db>
 					<username>shineisp</username>
 					<password>shineisp2013</password>
 				</database>
 			</config>
 		</shineisp>
 */
 public static function saveConfig($dbconfig, $version = null)
 {
     try {
         $xml = new SimpleXMLElement('<shineisp></shineisp>');
         if (!empty($version)) {
             $xml->addAttribute('version', $version);
         }
         $xml->addAttribute('setupdate', date('Ymdhis'));
         $config = $xml->addChild('config');
         // Database Configuration
         $database = $config->addChild('database');
         $database->addChild('hostname', $dbconfig->hostname);
         $database->addChild('username', $dbconfig->username);
         $database->addChild('password', $dbconfig->password);
         $database->addChild('database', $dbconfig->database);
         // Get the xml string
         $xmlstring = $xml->asXML();
         // Prettify and save the xml configuration
         $dom = new DOMDocument();
         $dom->loadXML($xmlstring);
         $dom->formatOutput = true;
         $dom->saveXML();
         // Save the config xml file
         if (@$dom->save(APPLICATION_PATH . "/configs/config.xml")) {
             Shineisp_Commons_Utilities::log("Update ShineISP config xml file");
             return true;
         } else {
             throw new Exception("Error on saving the xml file in " . APPLICATION_PATH . "/configs/config.xml <br/>Please check the folder permissions");
         }
     } catch (Exception $e) {
         throw new Exception($e->getMessage());
     }
     return false;
 }
    function testAddFunctionMultiple()
    {
        $server = new Zend_Soap_AutoDiscover();
        $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
        $server->addFunction('Zend_Soap_AutoDiscover_TestFunc2');
        $server->addFunction('Zend_Soap_AutoDiscover_TestFunc3');
        $server->addFunction('Zend_Soap_AutoDiscover_TestFunc4');
        $server->addFunction('Zend_Soap_AutoDiscover_TestFunc5');
        $server->addFunction('Zend_Soap_AutoDiscover_TestFunc6');
        $server->addFunction('Zend_Soap_AutoDiscover_TestFunc7');
        $server->addFunction('Zend_Soap_AutoDiscover_TestFunc9');
        $dom = new DOMDocument();
        ob_start();
        $server->handle();
        $dom->loadXML(ob_get_contents());
        $dom->save(dirname(__FILE__) . '/addfunction2.wsdl');
        ob_end_clean();
        $parts = explode('.', basename($_SERVER['SCRIPT_NAME']));
        $name = $parts[0];
        $wsdl = '<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://' . $_SERVER['PHP_SELF'] . '" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" name="' . $name . '" targetNamespace="http://' . $_SERVER['PHP_SELF'] . '"><portType name="' . $name . 'Port"><operation name="Zend_Soap_AutoDiscover_TestFunc"><input message="tns:Zend_Soap_AutoDiscover_TestFuncRequest"/><output message="tns:Zend_Soap_AutoDiscover_TestFuncResponse"/></operation><operation name="Zend_Soap_AutoDiscover_TestFunc2"><input message="tns:Zend_Soap_AutoDiscover_TestFunc2Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc2Response"/></operation><operation name="Zend_Soap_AutoDiscover_TestFunc3"><input message="tns:Zend_Soap_AutoDiscover_TestFunc3Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc3Response"/></operation><operation name="Zend_Soap_AutoDiscover_TestFunc4"><input message="tns:Zend_Soap_AutoDiscover_TestFunc4Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc4Response"/></operation><operation name="Zend_Soap_AutoDiscover_TestFunc5"><input message="tns:Zend_Soap_AutoDiscover_TestFunc5Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc5Response"/></operation><operation name="Zend_Soap_AutoDiscover_TestFunc6"><input message="tns:Zend_Soap_AutoDiscover_TestFunc6Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc6Response"/></operation><operation name="Zend_Soap_AutoDiscover_TestFunc7"><input message="tns:Zend_Soap_AutoDiscover_TestFunc7Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc7Response"/></operation><operation name="Zend_Soap_AutoDiscover_TestFunc9"><input message="tns:Zend_Soap_AutoDiscover_TestFunc9Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc9Response"/></operation></portType><binding name="' . $name . 'Binding" type="tns:' . $name . 'Port"><soap:operation soapAction="http://' . $_SERVER['PHP_SELF'] . '#Zend_Soap_AutoDiscover_TestFunc9"/><soap:operation soapAction="http://' . $_SERVER['PHP_SELF'] . '#Zend_Soap_AutoDiscover_TestFunc7"/><soap:operation soapAction="http://' . $_SERVER['PHP_SELF'] . '#Zend_Soap_AutoDiscover_TestFunc6"/><soap:operation soapAction="http://' . $_SERVER['PHP_SELF'] . '#Zend_Soap_AutoDiscover_TestFunc5"/><soap:operation soapAction="http://' . $_SERVER['PHP_SELF'] . '#Zend_Soap_AutoDiscover_TestFunc4"/><soap:operation soapAction="http://' . $_SERVER['PHP_SELF'] . '#Zend_Soap_AutoDiscover_TestFunc3"/><soap:operation soapAction="http://' . $_SERVER['PHP_SELF'] . '#Zend_Soap_AutoDiscover_TestFunc2"/><soap:operation soapAction="http://' . $_SERVER['PHP_SELF'] . '#Zend_Soap_AutoDiscover_TestFunc"/><soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/><operation name="Zend_Soap_AutoDiscover_TestFunc"><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation name="Zend_Soap_AutoDiscover_TestFunc2"><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation name="Zend_Soap_AutoDiscover_TestFunc3"><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation name="Zend_Soap_AutoDiscover_TestFunc4"><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation name="Zend_Soap_AutoDiscover_TestFunc5"><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation name="Zend_Soap_AutoDiscover_TestFunc6"><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation name="Zend_Soap_AutoDiscover_TestFunc7"><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation name="Zend_Soap_AutoDiscover_TestFunc9"><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation></binding><service name="' . $name . 'Service"><port name="' . $name . 'Port" binding="tns:' . $name . 'Binding"><soap:address location="http://' . $_SERVER['PHP_SELF'] . '"/></port></service><message name="Zend_Soap_AutoDiscover_TestFuncRequest"><part name="who" type="xsd:string"/></message><message name="Zend_Soap_AutoDiscover_TestFuncResponse"><part name="Zend_Soap_AutoDiscover_TestFuncReturn" type="xsd:string"/></message><message name="Zend_Soap_AutoDiscover_TestFunc2Request"/><message name="Zend_Soap_AutoDiscover_TestFunc3Request"/><message name="Zend_Soap_AutoDiscover_TestFunc3Response"><part name="Zend_Soap_AutoDiscover_TestFunc3Return" type="xsd:boolean"/></message><message name="Zend_Soap_AutoDiscover_TestFunc4Request"/><message name="Zend_Soap_AutoDiscover_TestFunc4Response"><part name="Zend_Soap_AutoDiscover_TestFunc4Return" type="xsd:boolean"/></message><message name="Zend_Soap_AutoDiscover_TestFunc5Request"/><message name="Zend_Soap_AutoDiscover_TestFunc5Response"><part name="Zend_Soap_AutoDiscover_TestFunc5Return" type="xsd:int"/></message><message name="Zend_Soap_AutoDiscover_TestFunc6Request"/><message name="Zend_Soap_AutoDiscover_TestFunc6Response"><part name="Zend_Soap_AutoDiscover_TestFunc6Return" type="xsd:string"/></message><message name="Zend_Soap_AutoDiscover_TestFunc7Request"/><message name="Zend_Soap_AutoDiscover_TestFunc7Response"><part name="Zend_Soap_AutoDiscover_TestFunc7Return" type="soap-enc:Array"/></message><message name="Zend_Soap_AutoDiscover_TestFunc9Request"><part name="foo" type="xsd:string"/><part name="bar" type="xsd:string"/></message><message name="Zend_Soap_AutoDiscover_TestFunc9Response"><part name="Zend_Soap_AutoDiscover_TestFunc9Return" type="xsd:string"/></message></definitions>
';
        $this->assertEquals($wsdl, $dom->saveXML(), "Bad WSDL generated");
        $this->assertTrue($dom->schemaValidate(dirname(__FILE__) . '/schemas/wsdl.xsd'), "WSDL Did not validate");
    }
Esempio n. 25
0
function add_to_xml($file, $title, $author, $price, $rating)
{
    $doc = new DOMDocument();
    $doc->Load($file);
    $list = $doc->getElementsByTagName("list")->item(0);
    $newid = (int) $list->getElementsByTagName("lastindex")->item(0)->textContent + 1;
    //echo $newid;
    $lastindex = $list->getElementsByTagName("lastindex")->item(0);
    $list->removeChild($lastindex);
    $newLastIndex = $doc->createElement("lastindex");
    $newLastIndex->appendChild($doc->createTextNode($newid));
    $list->appendChild($newLastIndex);
    //$list->getElementsByTagName("lastindex")->item(0)->appendChild($doc->createTextNode($newid));
    $newElement = $doc->createElement("item");
    $list->appendChild($newElement);
    $idd = $doc->createElement("id");
    $idd->appendChild($doc->createTextNode($newid));
    $newElement->appendChild($idd);
    $t = $doc->createElement("title");
    $t->appendChild($doc->createTextNode($title));
    $newElement->appendChild($t);
    $au = $doc->createElement("author");
    $au->appendChild($doc->createTextNode($author));
    $newElement->appendChild($au);
    $pri = $doc->createElement("price");
    $pri->appendChild($doc->createTextNode($price));
    $newElement->appendChild($pri);
    $ra = $doc->createElement("rating");
    $ra->appendChild($doc->createTextNode($rating));
    $newElement->appendChild($ra);
    $doc->save($file);
}
Esempio n. 26
0
function changeApplicationXmlVersions($file, $versionNum, $subver)
{
    $verStr = $versionNum . "_" . $subver;
    $newFiles = getNewFileName();
    $doc = new DOMDocument();
    $doc->load($file);
    $assests = $doc->getElementsByTagName("asset");
    $modules = $doc->getElementsByTagName("module");
    foreach ($newFiles as $nfi) {
        foreach ($assests as $ai) {
            $src = $ai->getAttribute("src");
            if (strpos($src, $nfi) !== false) {
                //echo "ok<br />";
                $ai->setAttribute("version", $verStr);
            }
            $src = $ai->nodeValue;
            if (strpos($src, $nfi) !== false) {
                $ai->setAttribute("version", $verStr);
                //echo "ok<br />";
            }
        }
        foreach ($modules as $mi) {
            $src = $mi->getAttribute("src");
            if (strpos($src, $nfi) !== false) {
                $mi->setAttribute("version", $verStr);
                //echo "ok  $nfi<br />";
            }
        }
    }
    $doc->save($file);
}
Esempio n. 27
0
 /**
  * Generate TestCase XML
  */
 public function generateXml()
 {
     $xml = simplexml_load_file(__DIR__ . '/testcase.xml');
     $xmlObject = new \SimpleXMLElement($xml->asXML());
     foreach ($xmlObject as $item) {
         $data = $this->getTicketData((array) $item);
         foreach ($data as $key => $field) {
             if ($item->xpath($key)) {
                 continue;
             }
             if (!is_array($field)) {
                 $item->addChild($key, $field);
             } else {
                 $node = $item->addChild($key);
                 foreach ($field as $value) {
                     $node->addChild(substr($key, 0, -1), $value);
                 }
             }
         }
         $this->cnt++;
     }
     // Format XML file
     $dom = new \DOMDocument("1.0");
     $dom->preserveWhiteSpace = false;
     $dom->formatOutput = true;
     $dom->loadXML($xmlObject->asXML());
     $dom->save(__DIR__ . '/testcase.xml');
     \Mtf\Util\Generate\GenerateResult::addResult('Test Case Tickets', $this->cnt);
 }
Esempio n. 28
0
function report($reportDir)
{
    global $browserNum;
    /* for junit report,根据配置文件里设置的分隔符来分割结果  */
    $paras = explode(ConfigTest::$splitChar, $_POST['config']);
    foreach ($paras as $para) {
        if (preg_match("/^browser=/", $para)) {
            $currBrowser = str_replace('browser=', '', $para);
        } elseif (preg_match("/^browserNum=/", $para)) {
            $browserNum = str_replace('browserNum=', '', $para);
        }
        if (!$currBrowser) {
            $currBrowser = "SH12HNX01484_SystemBrowser";
        }
    }
    //        if ( !$currBrowser ) {
    //            echo "please set para browser\n";
    //        }
    $dom = new DOMDocument('1.0', 'utf-8');
    $suite = $dom->appendChild($dom->createElement('testsuite'));
    $suite->setAttribute("name", $currBrowser);
    $failures = 0;
    $tests = 0;
    $time = 0;
    foreach ($_POST as $key => $value) {
        if ($key == 'config' || $key == "isJS") {
            continue;
        }
        $info = explode(",", $value);
        $casetime = ($info[4] - $info[3]) / 1000;
        $time += $casetime;
        $tests++;
        $failure = (int) $info[0];
        $case = $suite->appendChild($dom->createElement('testcase'));
        $case->setAttribute("name", $key);
        $case->setAttribute("time", $casetime);
        $case->setAttribute("cov", $info[2]);
        $case->setAttribute('failNumber', $info[0]);
        $case->setAttribute('totalNumber', $info[1]);
        //            $case->setAttribute( 'recordCovForBrowser' , $info[ 5 ] );
        $case->setAttribute('browserInfo', $currBrowser);
        $case->setAttribute('hostInfo', ConfigTest::$BROWSERS[$currBrowser][0]);
        if ($failure > 0) {
            $failures++;
            $failinfo = $case->appendChild($dom->createElement('failure'));
            $failinfo->setAttribute('type', 'junit.framework.AssertionFailedError');
            //$kiss = join( "." , split( "_" , $key ) );
            //$failinfo->appendChild( new DOMText( $value ) );
            $failinfo->appendChild(new DOMText("<a href=\"\">run</a>"));
        }
    }
    $suite->setAttribute('time', $time);
    $suite->setAttribute('failures', $failures);
    $suite->setAttribute('tests', $tests);
    if (!is_dir($reportDir)) {
        mkdir($reportDir);
    }
    $dom->save($reportDir . $currBrowser . ".xml");
}
Esempio n. 29
0
 /**
  * Finally save image
  * 
  * @param string $file Destination filename
  * @return void
  */
 public function render($file)
 {
     $this->createDocument();
     $this->drawAllTexts();
     // Embed used glyphs
     $this->font->addFontToDocument($this->dom);
     $this->dom->save($file);
 }
Esempio n. 30
0
 /**
  * Invokes writeXml().
  *
  * Writes Bamboo failure XML to file.
  *
  * @param $xml
  */
 public function writeXml($xml)
 {
     $doc = new DOMDocument();
     $doc->preserveWhiteSpace = false;
     $doc->loadXML($xml);
     $doc->formatOutput = true;
     $doc->save('xml/report.xml');
 }