Example #1
0
<?php

$dom = new domdocument();
$data = file_get_contents(dirname(__FILE__) . "/xinclude.xml");
$reldir = str_replace(getcwd(), ".", dirname(__FILE__));
if (DIRECTORY_SEPARATOR == '\\') {
    $reldir = str_replace('\\', "/", $reldir);
}
$data = str_replace('compress.zlib://ext/dom/tests/', 'compress.zlib://' . $reldir . "/", $data);
$dom->loadXML($data);
$dom->xinclude();
print $dom->saveXML() . "\n";
foreach ($dom->documentElement->childNodes as $node) {
    print $node->nodeName . "\n";
}
Example #2
0
function edit_show()
{
    $id = post('id');
    $arr = explode('-', $id);
    $xml_path = S_TPL_PATH . 'index/config.xml';
    $xml = new domdocument();
    $xml->load($xml_path);
    $tag = $xml->getelementsbytagname('site')->item(0)->getelementsbytagname('*');
    $len = $tag->length;
    $page_name = '';
    $page_node = '';
    $flag = 0;
    for ($i = 0; $i < $len; $i++) {
        $node_name = $tag->item($i)->nodeName;
        $node_text = str_replace('*', '', $tag->item($i)->nodeValue);
        if ($node_name == $arr[0]) {
            $flag = 1;
        } elseif ($node_name != 'module') {
            $flag = 0;
        }
        if ($flag == 1 && $node_name == 'module' && $node_text == $arr[1]) {
            if (intval($arr[2])) {
                $tag->item($i)->nodeValue = $node_text;
                edit_tpl_show($arr[0], $arr[1], 1);
            } else {
                $tag->item($i)->nodeValue = '*' . $node_text;
                edit_tpl_show($arr[0], $arr[1], 0);
            }
        }
    }
    file_put_contents($xml_path, $xml->saveXML());
    echo 1;
}
Example #3
0
<?php

$dom = new domdocument();
$dom->loadHTMLFile(dirname(__FILE__) . "/test.html");
print "--- save as XML\n";
print adjustDoctype($dom->saveXML());
print "--- save as HTML\n";
print adjustDoctype($dom->saveHTML());
function adjustDoctype($xml)
{
    return str_replace(array("DOCTYPE HTML", '<p>', '</p>'), array("DOCTYPE html", '', ''), $xml);
}
Example #4
0
 private static function tidyUpModuleDom($string)
 {
     $dom = new domdocument();
     @$dom->loadHTML("<html><body>" . $string . "</body></html>");
     $string = '';
     foreach ($dom->documentElement->firstChild->childNodes as $child) {
         $string .= $dom->saveXML($child);
     }
     return $string;
 }
Example #5
0
<?php

$dom = new domdocument();
$dom->load("compress.zlib://" . dirname(__FILE__) . "/book.xml.gz");
print $dom->saveXML();