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


PHP DOMDocument::createCDATASection方法代码示例

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


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

示例1: createRuleElement

 /**
  * Creates a rule element
  *
  * @param RuleModel $model
  * @return \DOMElement
  */
 private function createRuleElement($model)
 {
     $rule = $this->doc->createElement('rule');
     $type = $this->doc->createElement('type');
     $typeValue = $this->doc->createCDATASection($model->type);
     $type->appendChild($typeValue);
     $selector = $this->doc->createElement('selector');
     $selectorValue = $this->doc->createCDATASection($model->selector);
     $selector->appendChild($selectorValue);
     $enable_replace = $this->doc->createElement('enable_replace');
     $enable_replace->nodeValue = $model->enable_replace ? 'true' : 'false';
     $replace_directives = $this->doc->createElement('replace_directives');
     $replace_directivesValue = $this->doc->createCDATASection($model->replace_directives);
     $replace_directives->appendChild($replace_directivesValue);
     $enable_add = $this->doc->createElement('enable_add');
     $enable_add->nodeValue = $model->enable_add ? 'true' : 'false';
     $add_directives = $this->doc->createElement('add_directives');
     $add_directivesValue = $this->doc->createCDATASection($model->add_directives);
     $add_directives->appendChild($add_directivesValue);
     $published = $this->doc->createElement('published');
     $published->nodeValue = $model->published ? 'true' : 'false';
     $rule->appendChild($type);
     $rule->appendChild($selector);
     $rule->appendChild($enable_replace);
     $rule->appendChild($replace_directives);
     $rule->appendChild($enable_add);
     $rule->appendChild($add_directives);
     $rule->appendChild($published);
     return $rule;
 }
开发者ID:toflar,项目名称:contao-css-class-replacer,代码行数:36,代码来源:XmlExporter.php

示例2: createDOMElement

 /**
  * @param mixed $source
  * @param string $tagName
  * @param DOMDocument $document
  * @return DOMNode
  */
 private static function createDOMElement($source, $tagName, \DOMDocument $document)
 {
     if (!is_array($source)) {
         $element = $document->createElement($tagName);
         $element->appendChild($document->createCDATASection($source));
         return $element;
     }
     $element = $document->createElement($tagName);
     foreach ($source as $key => $value) {
         if (is_string($key)) {
             if ($key == self::ATTRIBUTES) {
                 foreach ($value as $attributeName => $attributeValue) {
                     $element->setAttribute($attributeName, $attributeValue);
                 }
             } else {
                 if ($key == self::CONTENT) {
                     $element->appendChild($document->createCDATASection($value));
                 } else {
                     foreach (is_array($value) ? $value : array($value) as $elementKey => $elementValue) {
                         $element->appendChild(self::createDOMElement($elementValue, $key, $document));
                     }
                 }
             }
         } else {
             $element->appendChild(self::createDOMElement($value, $tagName, $document));
         }
     }
     return $element;
 }
开发者ID:juaniiie,项目名称:mwi,代码行数:35,代码来源:dom.php

示例3: createXmlElement

 public function createXmlElement(DOMDocument $xmlDoc)
 {
     if (!$xmlDoc instanceof DOMDocument) {
         throw new Exception('', self::ERROR_INVALID_PARAMETER);
     }
     $xmlItemElem = $xmlDoc->createElement('item');
     if ($this->code == null || $this->name == null || $this->measurment == null || $this->quantity == null || $this->price == null || $this->vat == null) {
         throw new Exception('Invalid property', self::ERROR_INVALID_PROPERTY);
     }
     $xmlElem = $xmlDoc->createElement('code');
     $xmlElem->appendChild($xmlDoc->createCDATASection(urlencode($this->code)));
     $xmlItemElem->appendChild($xmlElem);
     $xmlElem = $xmlDoc->createElement('name');
     $xmlElem->appendChild($xmlDoc->createCDATASection(urlencode($this->name)));
     $xmlItemElem->appendChild($xmlElem);
     $xmlElem = $xmlDoc->createElement('measurment');
     $xmlElem->appendChild($xmlDoc->createCDATASection(urlencode($this->measurment)));
     $xmlItemElem->appendChild($xmlElem);
     $xmlElem = $xmlDoc->createElement('quantity');
     $xmlElem->nodeValue = $this->quantity;
     $xmlItemElem->appendChild($xmlElem);
     $xmlElem = $xmlDoc->createElement('price');
     $xmlElem->nodeValue = $this->price;
     $xmlItemElem->appendChild($xmlElem);
     $xmlElem = $xmlDoc->createElement('vat');
     $xmlElem->nodeValue = $this->vat;
     $xmlItemElem->appendChild($xmlElem);
     return $xmlItemElem;
 }
开发者ID:bardascat,项目名称:blogify,代码行数:29,代码来源:Item.php

示例4: format

 /**
  * Format field
  *
  * @param Field         $field A field instance
  * @param ItemInterface $item  An entity instance
  * 
  * @return string
  */
 protected function format(Field $field, ItemInterface $item)
 {
     $name = $field->getName();
     $method = $field->getMethod();
     $value = $item->{$method}();
     if ($field->get('cdata')) {
         $value = $this->dom->createCDATASection($value);
         $element = $this->dom->createElement($name);
         $element->appendChild($value);
     } else {
         if ($field->get('attribute')) {
             if (!$field->get('attribute_name')) {
                 throw new \InvalidArgumentException("'attribute' parameter required an 'attribute_name' parameter.");
             }
             $element = $this->dom->createElement($name);
             $element->setAttribute($field->get('attribute_name'), $item->getFeedItemLink());
         } else {
             if ($format = $field->get('date_format')) {
                 $value = $value->format($format);
             }
             $element = $this->dom->createElement($name, $value);
         }
     }
     return $element;
 }
开发者ID:thomask,项目名称:feedbundle,代码行数:33,代码来源:Formatter.php

示例5: doLog

 /**
  * Short description of method doLog
  *
  * @access public
  * @author Joel Bout, <joel.bout@tudor.lu>
  * @param  Item item
  * @return mixed
  */
 public function doLog(common_log_Item $item)
 {
     $doc = new DOMDocument();
     $doc->preserveWhiteSpace = false;
     $doc->formatOutput = true;
     $success = @$doc->load($this->filename);
     if (!$success) {
         $doc->loadXML('<events></events>');
     }
     $event_element = $doc->createElement("event");
     $message = $doc->createElement("description");
     $message->appendChild($doc->createCDATASection($item->getDescription()));
     $event_element->appendChild($message);
     $file = $doc->createElement("file");
     $file->appendChild($doc->createCDATASection($item->getCallerFile()));
     $event_element->appendChild($file);
     $line = $doc->createElement("line");
     $line->appendChild($doc->createCDATASection($item->getCallerLine()));
     $event_element->appendChild($line);
     $datetime = $doc->createElement("datetime");
     $datetime->appendChild($doc->createCDATASection($item->getDateTime()));
     $event_element->appendChild($datetime);
     $severity = $doc->createElement("severity");
     $severity->appendChild($doc->createCDATASection($item->getSeverity()));
     $event_element->appendChild($severity);
     $doc->documentElement->appendChild($event_element);
     @$doc->save($this->filename);
 }
开发者ID:nagyist,项目名称:generis,代码行数:36,代码来源:class.XMLAppender.php

示例6: actionCronXML

 public function actionCronXML()
 {
     echo "EXPORT STARTED\n";
     $xml = new \DOMDocument();
     $products = $xml->createElement('products');
     $xml->appendChild($products);
     $ids = $this->productManager->getAllIds();
     foreach ($ids as $id) {
         $product = $this->productFactory->createProduct();
         $product->loadById($id);
         $el = $xml->createElement('product');
         $id_el = $xml->createElement('id', $product->getId());
         $el->appendChild($id_el);
         $title_el = $xml->createElement('title');
         $title_el->appendChild($xml->createCDATASection($product->getTitle()));
         $el->appendChild($title_el);
         $sku_el = $xml->createElement('sku', $product->getSku());
         $el->appendChild($sku_el);
         $price_el = $xml->createElement('price', $product->getPrice());
         $el->appendChild($price_el);
         $category_el = $xml->createElement('category');
         $category_el->appendChild($xml->createCDATASection($product->getCategory()->getTitle()));
         $el->appendChild($category_el);
         $brand = $product->getBrand()->getTitle();
         if (false === empty($brand)) {
             $brand_el = $xml->createElement('brand');
             $brand_el->appendChild($xml->createCDATASection($brand));
             $el->appendChild($brand_el);
         }
         $warehouses_el = $xml->createElement('warehouses');
         $el->appendChild($warehouses_el);
         $checkString = $product->getId() . $product->getTitle() . $product->getSku() . $product->getPrice() . $product->getCategory()->getTitle() . $brand;
         foreach ($product->getWarehouses()->getAll() as $warehouse) {
             $warehouse_el = $xml->createElement('warehouse');
             $warehouses_el->appendChild($warehouse_el);
             $wid_el = $xml->createElement('id', $warehouse['id']);
             $warehouse_el->appendChild($wid_el);
             $total_el = $xml->createElement('total', $warehouse['total']);
             $warehouse_el->appendChild($total_el);
             $checkString .= $warehouse['id'] . $warehouse['total'];
         }
         $checksum = $xml->createElement('checksum', substr(md5($checkString), 0, 5));
         $el->appendChild($checksum);
         $products->appendChild($el);
     }
     echo "XML HAS BEEN CREATED\n";
     $file = TEMP_DIR . "/products.xml";
     $xml->save($file);
     echo "XML HAS BEEN SAVED\n";
     $this->ftpConnection->uploadFile($file);
     echo "XML HAS BEEN UPLOADED\n";
     unlink($file);
     echo "XML HAS BEEN DELETED\n";
     $this->terminate();
 }
开发者ID:pogodi,项目名称:Brain,代码行数:55,代码来源:ExporterPresenter.php

示例7: createAndAppendElement

 /**
  * Creates and appends an element to a parent element.
  *
  * @param \DOMElement $parentElement
  * @param string $dataElement
  * @param mixed $data
  */
 protected function createAndAppendElement(\DOMElement $parentElement, $dataElement, $data)
 {
     if (in_array(gettype($data), array('boolean', 'integer', 'double'))) {
         $dataElement = $this->domDoc->createElement($dataElement, $data);
     } else {
         $data = $this->domDoc->createCDATASection((string) $data);
         $dataElement = $this->domDoc->createElement($dataElement);
         $dataElement->appendChild($data);
     }
     $parentElement->appendChild($dataElement);
 }
开发者ID:adnamsplc,项目名称:verifone,代码行数:18,代码来源:AbstractRequest.php

示例8: createTranslationNode

 /**
  * Create a new trans-unit node.
  *
  * @param \DOMDocument $dom
  * @param int $id
  * @param string $key
  * @param string $value
  * @return \DOMElement
  */
 protected function createTranslationNode(\DOMDocument $dom, $id, $key, $value)
 {
     $translationNode = $dom->createElement('trans-unit');
     $translationNode->appendChild(new \DOMAttr('id', $id));
     $source = $dom->createElement('source');
     $source->appendChild($dom->createCDATASection($key));
     $translationNode->appendChild($source);
     $target = $dom->createElement('target');
     $target->appendChild($dom->createCDATASection($value));
     $translationNode->appendChild($target);
     return $translationNode;
 }
开发者ID:StuartApp,项目名称:LexikTranslationBundle,代码行数:21,代码来源:XliffExporter.php

示例9: populateFeedWithBatchData

 /**
  * Data returned from a child process at the batch level
  *
  * @param array $batchData
  */
 protected function populateFeedWithBatchData($batchData)
 {
     foreach ($batchData as $product) {
         $product_node = $this->_dom->createElement($this->productNodeName);
         foreach ($product as $feed_tag => $value) {
             $value = $this->processBatchField($feed_tag, $value);
             $field_element = $this->_dom->createElement($feed_tag);
             $cdata_node = $this->_dom->createCDATASection($value);
             $field_element->appendChild($cdata_node);
             $product_node->appendChild($field_element);
         }
         $this->_productsNode->appendChild($product_node);
     }
 }
开发者ID:shakhawat4g,项目名称:MagentoExtensions,代码行数:19,代码来源:Xml.php

示例10: toXML

 /**
  * Convert array to xml 
  *
  * @param $data array 
  *
  * @return string
  */
 private function toXML(array $data = null)
 {
     $el = $this->domDocument->createElement('data');
     $mRootNode = $this->domDocument->appendChild($el);
     foreach ($data as $unit) {
         $el = $this->domDocument->createElement('entry');
         $rootNode = $mRootNode->appendChild($el);
         foreach ($unit as $key => $value) {
             $name = $this->domDocument->createElement(self::PREFIX . $key);
             $rootNode->appendChild($name);
             $name->appendChild($this->domDocument->createCDATASection($value));
         }
     }
     return $this->domDocument;
 }
开发者ID:bdahlia,项目名称:uploader,代码行数:22,代码来源:XMLFormatter.php

示例11: format

 /**
  * {@inheritdoc}
  */
 protected function format(MessageCatalogue $messages, $domain)
 {
     $dom = new \DOMDocument('1.0', 'utf-8');
     $dom->formatOutput = true;
     $xliff = $dom->appendChild($dom->createElement('xliff'));
     $xliff->setAttribute('version', '1.2');
     $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');
     $xliffFile = $xliff->appendChild($dom->createElement('file'));
     $xliffFile->setAttribute('source-language', $messages->getLocale());
     $xliffFile->setAttribute('datatype', 'plaintext');
     $xliffFile->setAttribute('original', 'file.ext');
     $xliffBody = $xliffFile->appendChild($dom->createElement('body'));
     foreach ($messages->all($domain) as $source => $target) {
         $translation = $dom->createElement('trans-unit');
         $translation->setAttribute('id', md5($source));
         $translation->setAttribute('resname', $source);
         $s = $translation->appendChild($dom->createElement('source'));
         $s->appendChild($dom->createTextNode($source));
         // Does the target contain characters requiring a CDATA section?
         $text = 1 === preg_match('/[&<>]/', $target) ? $dom->createCDATASection($target) : $dom->createTextNode($target);
         $t = $translation->appendChild($dom->createElement('target'));
         $t->appendChild($text);
         $xliffBody->appendChild($translation);
     }
     return $dom->saveXML();
 }
开发者ID:kchhainarong,项目名称:chantuchP,代码行数:29,代码来源:XliffFileDumper.php

示例12: createTextNode

 private function createTextNode($data, $cdata = false)
 {
     if (!$cdata) {
         return $this->document->createTextNode($data);
     }
     return $this->document->createCDATASection($data);
 }
开发者ID:alekitto,项目名称:serializer,代码行数:7,代码来源:XmlSerializationVisitor.php

示例13: arrToXml

 private function arrToXml($arr, $dom = 0, $item = 0, $itemname = 'item')
 {
     if (!$dom) {
         $dom = new DOMDocument("1.0", 'gbk');
         $dom->formatOutput = true;
     }
     if (!$item) {
         $item = $dom->createElement("DOCUMENT");
         $dom->appendChild($item);
     }
     foreach ($arr as $key => $val) {
         if (is_string($key) && $key == 'pmschool') {
             $itemx = $item;
             $itemname = 'pmschool';
         } else {
             $itemx = $dom->createElement(is_string($key) ? $key : $itemname);
             $item->appendChild($itemx);
         }
         if (is_string($key) && $key == 'pschooltypeid') {
             $itemname = 'item';
         }
         if (!is_array($val)) {
             $text = $dom->createCDATASection($val);
             $itemx->appendChild($text);
         } else {
             $this->arrToXml($val, $dom, $itemx, $itemname);
         }
     }
     return $dom->saveXML();
 }
开发者ID:sdgdsffdsfff,项目名称:mytest,代码行数:30,代码来源:StaticSchool.php

示例14: convertArray

 /**
  * @internal internal array parser, turns any array into a DOMDocument
  *
  * @param unknown_type $node
  * @param unknown_type $parentNode
  */
 private function convertArray($node = false, $parentNode = false)
 {
     $toRemove = array();
     foreach ($node as $nodeName => $nodeValue) {
         if ($parentNode) {
             if (is_numeric($nodeName) && intval($nodeName) == $nodeName) {
                 $parentNode->parentNode->appendChild($newElement = $this->DOMDocument->createElement($parentNode->nodeName));
                 $toRemove[] = $parentNode;
             } else {
                 $parentNode->appendChild($newElement = $this->DOMDocument->createElement($nodeName));
             }
         } else {
             $this->DOMDocument->appendChild($newElement = $this->DOMDocument->createElement($nodeName));
         }
         if (is_array($nodeValue)) {
             $this->convertArray($nodeValue, $newElement);
         } else {
             if ($nodeValue == strip_tags($nodeValue)) {
                 $newTextNode = $this->DOMDocument->createTextNode($nodeValue);
                 $newElement->appendChild($newTextNode);
             } else {
                 $newCDATANode = $this->DOMDocument->createCDATASection($nodeValue);
                 $newElement->appendChild($newCDATANode);
             }
         }
     }
     foreach ($toRemove as $remove) {
         if (is_object($remove->parentNode)) {
             $remove->parentNode->removeChild($remove);
         }
     }
 }
开发者ID:uniteddiversity,项目名称:DebateHub,代码行数:38,代码来源:rss_php.php

示例15: visitEnterSelectorSequence

 /**
  * If here is already data in the buffer, add a separator before starting the next.
  *
  * @return boolean
  */
 public function visitEnterSelectorSequence()
 {
     if ($this->_current === $this->_dom->documentElement && $this->_current->hasChildNodes()) {
         $this->_current->appendChild($this->_dom->createElementNs($this->_xmlns, 'text'))->appendChild($this->_dom->createCDATASection(', '));
     }
     return $this->start($this->appendElement('selector'));
 }
开发者ID:ThomasWeinert,项目名称:PhpCss,代码行数:12,代码来源:Explain.php


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