当前位置: 首页>>代码示例>>PHP>>正文


PHP DOMDocument::normalize方法代码示例

本文整理汇总了PHP中DOMDocument::normalize方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMDocument::normalize方法的具体用法?PHP DOMDocument::normalize怎么用?PHP DOMDocument::normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DOMDocument的用法示例。


在下文中一共展示了DOMDocument::normalize方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: assertXMLEquals

 protected function assertXMLEquals($expect, $test)
 {
     $doc = new DOMDocument();
     $this->assertTrue($doc->loadXML($expect), "Can load {$expect}");
     $doc->normalize();
     $expect = $doc->saveXML();
     $doc = new DOMDocument();
     $this->assertTrue($doc->loadXML($test), "Can load {$test}");
     $doc->normalize();
     $test = $doc->saveXML();
     $this->assertEquals($expect, $test);
 }
开发者ID:gbisra,项目名称:Computer-r-us,代码行数:12,代码来源:config.php

示例2: process

 /**
  * HTML processor
  * @param string $source Source HTML
  * @param bool $clean Perform cleaning
  * @param bool $withHeaders Return full HTML page (true) or contents only (false)
  * @return string
  */
 public function process($source, $clean = true, $withHeaders = false)
 {
     if (!trim($source)) {
         return '';
     }
     /*try {
           $source = \Difra\Libs\ESAPI::encoder()->canonicalize( $source );
       } catch( \Exception $ex ) {
           return false;
       }*/
     // html to dom conversion
     $html = new \DOMDocument('1.0');
     libxml_use_internal_errors(true);
     $html->loadHTML('<?xml version = "1.0" encoding = "utf-8"?>' . $source);
     libxml_use_internal_errors(false);
     $html->normalize();
     // clean dom
     if ($clean) {
         $bodyList = $html->documentElement->getElementsByTagName('body');
         if ($bodyList->length and $bodyList->item(0)->childNodes->length) {
             $body = $bodyList->item(0);
             $replaceNodes = [];
             foreach ($body->childNodes as $node) {
                 $newReplaceNodes = $this->clean($node);
                 $replaceNodes = array_merge($replaceNodes, $newReplaceNodes);
             }
             if (!empty($replaceNodes)) {
                 foreach ($replaceNodes as $replaceNode) {
                     $this->replace($replaceNode);
                 }
             }
         } else {
             return false;
         }
     }
     // dom to html conversion
     if ($withHeaders) {
         $output = $html->saveHTML();
     } else {
         $newDom = new \DOMDocument();
         foreach ($html->documentElement->childNodes as $node) {
             if ($node->nodeName == 'body') {
                 foreach ($node->childNodes as $subNode) {
                     $newDom->appendChild($newDom->importNode($subNode, true));
                 }
             }
         }
         $output = $newDom->saveHTML();
         // TODO: convert xhtml to html5
     }
     return mb_convert_encoding($output, 'UTF-8', 'HTML-ENTITIES');
 }
开发者ID:difra-org,项目名称:difra,代码行数:59,代码来源:HTML.php

示例3: xmlDump

 public static function xmlDump($var)
 {
     $oDM = new DOMDocument();
     $oDM->loadXML($var);
     if ($oDM) {
         $oDM->formatOutput = true;
         $oDM->normalize();
         $var = $oDM->saveXML();
         $widget = new CTextHighlighter();
         $widget->language = 'xml';
         echo $widget->highlight(${$var});
     }
 }
开发者ID:niranjan2m,项目名称:Voyanga,代码行数:13,代码来源:VarDumper.php

示例4: formatXML

 public static function formatXML($xml)
 {
     libxml_use_internal_errors(true);
     $oDM = new DOMDocument();
     try {
         $load = @$oDM->loadXML($xml);
         if ($load) {
             $oDM->formatOutput = true;
             $oDM->normalize();
             $xml = $oDM->saveXML();
         }
     } catch (Exeption $e) {
     }
     return $xml;
 }
开发者ID:niranjan2m,项目名称:Voyanga,代码行数:15,代码来源:UtilsHelper.php

示例5: toXML

function toXML()
{
    global $sheet, $file;
    if ($sheet === null) {
        return;
    }
    $doc = new DOMDocument('1.0', 'utf-8');
    $doc->preserveWhiteSpace = false;
    $doc->formatOutput = true;
    $root = $doc->createElement("character");
    $doc->appendChild($root);
    $gear = $doc->createElement("gear");
    $root->appendChild($gear);
    $fileName = $file;
    foreach ($sheet as $key => $value) {
        switch ($key) {
            case "monk":
            case "priest":
            case "shaman":
            case "druid":
            case "warlock":
            case "warrior":
            case "hunter":
            case "deathknight":
            case "rogue":
            case "mage":
            case "paladin":
                $fileName = $value["value"];
                $root->setAttribute("name", $value["value"]);
                $root->setAttribute("class", $key);
                break;
            case "level":
                $root->setAttribute("level", $value["value"]);
                break;
            case "race":
                $root->setAttribute("race", $value["value"]);
                break;
            case "role":
                $root->setAttribute("role", $value["value"]);
                break;
            case "head":
            case "neck":
            case "shoulder":
            case "chest":
            case "waist":
            case "legs":
            case "feet":
            case "wrist":
            case "finger1":
            case "finger2":
            case "trinket1":
            case "trinket2":
            case "back":
            case "main_hand":
            case "off_hand":
                $e = $doc->createElement("item");
                $e->setAttribute("slot", $key);
                $vars = $value["vars"];
                foreach ($vars as $vkey => $vvalue) {
                    $e->setAttribute($vkey, $vvalue);
                }
                $e->appendChild($doc->createTextNode($value["value"]));
                $gear->appendChild($e);
                break;
            default:
        }
    }
    $doc->normalize();
    $length = strrpos($fileName, ".");
    if (!$length) {
        $length = strlen($fileName);
    }
    $f = substr($fileName, 0, $length) . ".xml";
    $doc->save($f);
    return $doc;
}
开发者ID:recognant,项目名称:guidesite,代码行数:76,代码来源:index.php

示例6: prettyprint

 /**
  * prettyprint -- get rid of superfluous namespace declarations
  * @param  DOMDocument $dom
  * @return DOMDocument       return cleaned DOM
  */
 private function prettyprint($dom)
 {
     $dom->normalize();
     $dom->preserveWhiteSpace = false;
     $dom->formatOutput = true;
     $outXML = $dom->saveXML();
     $dom->loadXML($outXML, LIBXML_NSCLEAN);
     return $dom;
 }
开发者ID:Nothorse,项目名称:Giles,代码行数:14,代码来源:opds.cls.php

示例7:

<txt>
\t<txt lines="1">
\t\t<txt lines="nope"></txt>
\t</txt>
\t<txt lines="0">
\t\t<txt lines="12"></txt>
\t  <txt lines="3">
\t    <txt lines-after="2"></txt>
\t    <txt></txt>
\t  </txt>
\t\t<txt lines-before="2"></txt>
\t</txt>
</txt>
EOS
);
$dom->normalize();
$xpath = new \DOMXPath($dom);
$root = $xpath->query('/txt')->item(0);
//$r = $xpath->evaluate(
//'.//txt[last() and ancestor::txt[last()]]',
//$root
//);
//$it = $root;
//$lines = 0;
//while(($it = $it->lastChild )&& $it instanceof DOMElement) {
//var_dump($it->getNodePath());
//if($it->hasAttribute('lines')) {
//$line = (int) $it->getAttribute('lines');
//var_dump($line);
//if($line > $lines) $lines = $line;
//}
开发者ID:ju1ius,项目名称:libphp,代码行数:31,代码来源:PlainText.php


注:本文中的DOMDocument::normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。