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


PHP DOMDocument::insertBefore方法代码示例

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


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

示例1: addStyleElementToDocument

 /**
  * Adds a style element with $css to $document.
  *
  * This method is protected to allow overriding.
  *
  * @see https://github.com/jjriv/emogrifier/issues/103
  *
  * @param \DOMDocument $document
  * @param string $css
  *
  * @return void
  */
 protected function addStyleElementToDocument(\DOMDocument $document, $css)
 {
     $styleElement = $document->createElement('style', $css);
     $styleAttribute = $document->createAttribute('type');
     $styleAttribute->value = 'text/css';
     $styleElement->appendChild($styleAttribute);
     $body = $document->getElementsByTagName('body')->item(0);
     if (!$body) {
         $body = $document->createElement('body');
         $document->insertBefore($body);
     }
     if ($this->appendStylesToBody) {
         $body->insertBefore($styleElement, $body->firstChild);
     } else {
         $head = $this->getOrCreateHeadElement($document);
         $head->appendChild($styleElement);
     }
 }
开发者ID:peterfox,项目名称:emogrifier,代码行数:30,代码来源:Emogrifier.php

示例2: viewCCD

function viewCCD($ccr, $raw = "no", $requested_by = "")
{
    global $pid;
    $ccr->preserveWhiteSpace = false;
    $ccr->formatOutput = true;
    $ccr->save(dirname(__FILE__) . '/generatedXml/ccrForCCD.xml');
    $xmlDom = new DOMDocument();
    $xmlDom->loadXML($ccr->saveXML());
    $ccr_ccd = new DOMDocument();
    $ccr_ccd->load(dirname(__FILE__) . '/ccd/ccr_ccd.xsl');
    $xslt = new XSLTProcessor();
    $xslt->importStylesheet($ccr_ccd);
    $ccd = new DOMDocument();
    $ccd->preserveWhiteSpace = false;
    $ccd->formatOutput = true;
    $ccd->loadXML($xslt->transformToXML($xmlDom));
    $ccd->save(dirname(__FILE__) . '/generatedXml/ccdDebug.xml');
    if ($raw == "yes") {
        // simply send the xml to a textarea (nice debugging tool)
        echo "<textarea rows='35' cols='500' style='width:95%' readonly>";
        echo $ccd->saveXml();
        echo "</textarea>";
        return;
    }
    if ($raw == "pure") {
        // send a zip file that contains a separate xml data file and xsl stylesheet
        if (!class_exists('ZipArchive')) {
            displayError(xl("ERROR: Missing ZipArchive PHP Module"));
            return;
        }
        $tempDir = $GLOBALS['temporary_files_dir'];
        $zipName = $tempDir . "/" . getReportFilename() . "-ccd.zip";
        if (file_exists($zipName)) {
            unlink($zipName);
        }
        $zip = new ZipArchive();
        if (!$zip) {
            displayError(xl("ERROR: Unable to Create Zip Archive."));
            return;
        }
        if ($zip->open($zipName, ZIPARCHIVE::CREATE)) {
            $zip->addFile("stylesheet/cda.xsl", "stylesheet/cda.xsl");
            $xmlName = $tempDir . "/" . getReportFilename() . "-ccd.xml";
            if (file_exists($xmlName)) {
                unlink($xmlName);
            }
            $e_styleSheet = $ccd->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="stylesheet/cda.xsl"');
            $ccd->insertBefore($e_styleSheet, $ccd->firstChild);
            $ccd->save($xmlName);
            $zip->addFile($xmlName, basename($xmlName));
            $zip->close();
            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Content-Type: application/force-download");
            header("Content-Length: " . filesize($zipName));
            header("Content-Disposition: attachment; filename=" . basename($zipName) . ";");
            header("Content-Description: File Transfer");
            readfile($zipName);
            unlink($zipName);
            unlink($xmlName);
            exit(0);
        } else {
            displayError(xl("ERROR: Unable to Create Zip Archive."));
            return;
        }
    }
    if (substr($raw, 0, 4) == "send") {
        $recipient = trim(stripslashes(substr($raw, 5)));
        $result = transmitCCD($ccd, $recipient, $requested_by);
        echo htmlspecialchars($result, ENT_NOQUOTES);
        return;
    }
    $ss = new DOMDocument();
    $ss->load(dirname(__FILE__) . "/stylesheet/cda.xsl");
    $xslt->importStyleSheet($ss);
    $html = $xslt->transformToXML($ccd);
    echo $html;
}
开发者ID:katopenzz,项目名称:openemr,代码行数:79,代码来源:createCCR.php

示例3: addMeta

 /**
  * Add a <?xyl-meta?> processing-instruction (only that).
  *
  * @param   array   $attributes    Attributes.
  * @return  void
  */
 public function addMeta(array $attributes)
 {
     $handle = null;
     foreach ($attributes as $key => $value) {
         $handle .= $key . '="' . str_replace('"', '\\"', $value) . '" ';
     }
     $this->_mowgli->insertBefore(new \DOMProcessingInstruction('xyl-meta', substr($handle, 0, -1)), $this->_mowgli->documentElement);
     return;
 }
开发者ID:Grummfy,项目名称:Central,代码行数:15,代码来源:Xyl.php

示例4: write

 /**
  * Writes the RDF file on the file system.
  *
  * @access public
  * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu>
  * @return mixed
  */
 public function write()
 {
     $targetPath = $this->getFilePath();
     $file = $this->getTranslationFile();
     $semanticNamespaces = array('rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#');
     $xmlNS = 'http://www.w3.org/XML/1998/namespace';
     $xmlnsNS = 'http://www.w3.org/2000/xmlns/';
     try {
         $targetFile = new DOMDocument('1.0', 'UTF-8');
         $targetFile->formatOutput = true;
         // Create the RDF root node and annotate if possible.
         $rdfNode = $targetFile->createElementNS($semanticNamespaces['rdf'], 'rdf:RDF');
         $targetFile->appendChild($rdfNode);
         $rootAnnotations = $this->getTranslationFile()->getAnnotations();
         if (count($rootAnnotations)) {
             $annotationsString = tao_helpers_translation_RDFUtils::serializeAnnotations($rootAnnotations);
             $annotationsNode = $targetFile->createComment("\n    " . $annotationsString . "\n");
             $targetFile->insertBefore($annotationsNode, $rdfNode);
         }
         $rdfNode->setAttributeNS($xmlNS, 'xml:base', $file->getBase());
         $rdfNode->setAttributeNS($xmlnsNS, 'xmlns:rdfs', $semanticNamespaces['rdfs']);
         $xPath = new DOMXPath($targetFile);
         $xPath->registerNamespace($semanticNamespaces['rdf'], 'rdf');
         $xPath->registerNamespace($semanticNamespaces['rdfs'], 'rdfs');
         foreach ($file->getTranslationUnits() as $tu) {
             // Look if the predicate is a semantic namespace.
             $uri = explode('#', $tu->getPredicate());
             if (count($uri) == 2) {
                 $namespace = $uri[0] . '#';
                 $qName = $uri[1];
                 if (($searchedNS = array_search($namespace, $semanticNamespaces)) !== false) {
                     $tuNode = $targetFile->createElement("{$searchedNS}:{$qName}");
                     $tuNode->setAttributeNS($xmlNS, 'xml:lang', $tu->getTargetLanguage());
                     $cdataValue = $tu->getTarget() == '' ? $tu->getSource() : $tu->getTarget();
                     $tuNodeValue = $targetFile->createCDATASection($cdataValue);
                     $tuNode->appendChild($tuNodeValue);
                     // Check if an rdf:Description exists for
                     // the target of the TranslationUnit.
                     $subject = $tu->getSubject();
                     $result = $xPath->query("//rdf:Description[@rdf:about='{$subject}']");
                     if ($result->length > 0) {
                         // Append to the existing rdf:Description.
                         $existingDescription = $result->item(0);
                         $existingDescription->appendChild($tuNode);
                     } else {
                         // Append to a new rdf:Description node.
                         $descriptionNode = $targetFile->createElementNS($semanticNamespaces['rdf'], 'rdf:Description');
                         $descriptionNode->setAttributeNS($semanticNamespaces['rdf'], 'rdf:about', $subject);
                         $descriptionNode->appendChild($tuNode);
                         $rdfNode->appendChild($descriptionNode);
                     }
                     // Finally add annotations.
                     $annotations = $tu->getAnnotations();
                     if (count($annotations) > 0) {
                         $annotationString = "\n    " . tao_helpers_translation_RDFUtils::serializeAnnotations($annotations) . "\n    ";
                         $annotationNode = $targetFile->createComment($annotationString);
                         $tuNode->parentNode->insertBefore($annotationNode, $tuNode);
                     }
                 }
             }
         }
         $targetFile->save($targetPath);
     } catch (DOMException $e) {
         throw new tao_helpers_translation_TranslationException("An error occured while writing the RDF File at '{$targetPath}'.");
     }
 }
开发者ID:nagyist,项目名称:tao-core,代码行数:73,代码来源:class.RDFFileWriter.php

示例5: render

 public function render()
 {
     $dom = $dom = new \DOMDocument('1.0');
     $header = $dom->createElement('h1', $this->_name);
     $dom->appendChild($header);
     $form = $dom->createElement('form');
     $form->setAttribute('action', $this->_action);
     $form->setAttribute('method', $this->_method);
     $form->setAttribute('id', $this->_id);
     if ($this->_enctype != null) {
         $form->setAttribute('enctype', $this->_enctype);
     }
     $dom->appendChild($form);
     foreach ($this->_fields as $name => $field) {
         if (($field->type == self::FIELD_INPUT_HIDDEN || $field->type == self::FIELD_NOT_RENDER) && $field->error != null) {
             $err = $dom->createElement('div', $field->error);
             $err->setAttribute('class', 'form-field-error');
             $dom->insertBefore($err, $form);
         }
         if (($rendered = $this->createField($name)->render($dom)) != null) {
             $form->appendChild($rendered);
         }
     }
     return $dom->saveHTML();
 }
开发者ID:nazarov-andrey,项目名称:crm,代码行数:25,代码来源:Form.php

示例6: DOMDocument

<?php

$doc = new DOMDocument();
$node1 = $doc->createElement('div');
$node2 = $doc->createElement('div');
$res1 = $doc->appendChild($node1);
$res2 = $doc->insertBefore($node2, $res1);
$res3 = $doc->insertBefore($node1, $node2);
var_dump($doc->saveXML());
开发者ID:badlamer,项目名称:hhvm,代码行数:9,代码来源:domnode_insertbefore_same.php


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