/**
  * 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;
 }
Example #2
0
File: dom.php Project: juaniiie/mwi
 /**
  * @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;
 }
Example #3
0
 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;
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
 /**
  * Short description of method doLog
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @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);
 }
Example #6
0
 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();
 }
Example #7
0
 /**
  * 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);
 }
 /**
  * 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;
 }
Example #9
0
 /**
  * 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);
     }
 }
Example #10
0
 /**
  * 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;
 }
 /**
  * {@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();
 }
 private function createTextNode($data, $cdata = false)
 {
     if (!$cdata) {
         return $this->document->createTextNode($data);
     }
     return $this->document->createCDATASection($data);
 }
Example #13
0
 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();
 }
Example #14
0
 /**
  * @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);
         }
     }
 }
Example #15
0
 /**
  * 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'));
 }
Example #16
0
 /**
  * Format an item field
  *
  * @param ItemFieldInterface $field An item field instance
  * @param ItemInterface      $item  An entity instance
  * @param string             $value A field value
  *
  * @return \DOMElement
  *
  * @throws \InvalidArgumentException
  */
 protected function formatWithOptions(ItemFieldInterface $field, ItemInterface $item, $value)
 {
     $element = null;
     $name = $field->getName();
     if ($field->get('translatable')) {
         $value = $this->translate($value);
     }
     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'), $value);
         } else {
             if ($format = $field->get('date_format')) {
                 if (!$value instanceof \DateTime) {
                     throw new \InvalidArgumentException(sprintf('Field "%s" should be a DateTime instance.', $name));
                 }
                 $value = $value->format($format);
             }
             $element = $this->dom->createElement($name, $value);
         }
     }
     $this->addAttributes($element, $field, $item);
     return $element;
 }
Example #17
0
 public function render($caption_set, $file = false)
 {
     $dom = new \DOMDocument("1.0");
     $dom->formatOutput = true;
     $root = $dom->createElement('tt');
     $dom->appendChild($root);
     $body = $dom->createElement('body');
     $root->appendChild($body);
     $xmlns = $dom->createAttribute('xmlns');
     $xmlns->appendChild($dom->createTextNode('http://www.w3.org/ns/ttml'));
     $root->appendChild($xmlns);
     $div = $dom->createElement('div');
     $body->appendChild($div);
     foreach ($caption_set->captions() as $index => $caption) {
         $entry = $dom->createElement('p');
         $from = $dom->createAttribute('begin');
         $from->appendChild($dom->createTextNode(DfxpHelper::time_to_string($caption->start())));
         $entry->appendChild($from);
         $to = $dom->createAttribute('end');
         $to->appendChild($dom->createTextNode(DfxpHelper::time_to_string($caption->end())));
         $entry->appendChild($to);
         $entry->appendChild($dom->createCDATASection($caption->text()));
         $div->appendChild($entry);
     }
     if ($file) {
         return file_put_contents($file, $dom->saveXML());
     } else {
         return $dom->saveHTML();
     }
 }
Example #18
0
    /**
     * @param \DOMNode $node
     * @param string   $val
     *
     * @return bool
     */
    final protected function appendCData(\DOMNode $node, $val)
    {
        $nodeText = $this->dom->createCDATASection($val);
        $node->appendChild($nodeText);

        return true;
    }
 /**
  * @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);
         // Handle NULL bytes
         if (strpos($source, "") !== false) {
             $source = 'json_encoded::' . json_encode($source);
             $element->setAttribute('encoded', 'json');
         }
         $element->appendChild($document->createCDATASection($source));
         return $element;
     }
     $element = $document->createElement($tagName);
     foreach ($source as $key => $value) {
         if (is_string($key) && !is_numeric($key)) {
             if ($key === self::ATTRIBUTES) {
                 foreach ($value as $attributeName => $attributeValue) {
                     $element->setAttribute($attributeName, $attributeValue);
                 }
             } elseif ($key === self::CONTENT) {
                 $element->appendChild($document->createCDATASection($value));
             } elseif (is_string($value) && !is_numeric($value)) {
                 $element->appendChild(self::createDOMElement($value, $key, $document));
             } elseif (is_array($value) && count($value)) {
                 $keyNode = $document->createElement($key);
                 foreach ($value as $elementKey => $elementValue) {
                     if (is_string($elementKey) && !is_numeric($elementKey)) {
                         $keyNode->appendChild(self::createDOMElement($elementValue, $elementKey, $document));
                     } else {
                         $element->appendChild(self::createDOMElement($elementValue, $key, $document));
                     }
                 }
                 if ($keyNode->hasChildNodes()) {
                     $element->appendChild($keyNode);
                 }
             } else {
                 if (is_bool($value)) {
                     $value = $value ? 'true' : 'false';
                 }
                 $element->appendChild(self::createDOMElement($value, $key, $document));
             }
         } else {
             $element->appendChild(self::createDOMElement($value, $tagName, $document));
         }
     }
     return $element;
 }
 private function createXml($action)
 {
     // Init the document
     $this->_doc = new DOMDocument();
     $this->_doc->formatOutput = true;
     $this->_doc->encoding = "UTF-8";
     // Build the feed
     $feed = $this->_doc->createElement('feed');
     $export = $this->_doc->createElement('export');
     $feed->appendChild($export);
     $media = $this->_doc->createElement('media');
     $export->appendChild($media);
     $this->setAttribute($media, "co_guid", $this->referenceId);
     $this->setAttribute($media, "entry_id", $this->entryId);
     if ($action === self::ACTION_DELETE) {
         $this->setAttribute($media, "action", self::ACTION_DELETE);
     } else {
         $this->setAttribute($media, "action", self::ACTION_SUBMIT);
     }
     if ($action != self::ACTION_DELETE) {
         //$isActive = $this->fieldValues[TvinciDistributionField::ACTIVATE_PUBLISHING];
         // agreed that the is_active and erase will be hard coded for first phase
         $this->setAttribute($media, "is_active", "true");
         $this->setAttribute($media, "erase", "false");
         $media->appendChild($this->createBasicElement());
         $media->appendChild($this->createStructureElement());
         $media->appendChild($this->createFilesElement());
     }
     // Wrap as a CDATA section
     $feedAsXml = $this->_doc->saveXML($feed);
     $xslt = file_get_contents(__DIR__ . "/../xml/tvinci_default.xslt");
     $feedAsXml = $this->transformXml($feedAsXml, $xslt);
     $data = $this->_doc->createElement('data');
     $data->appendChild($this->_doc->createCDATASection($feedAsXml));
     // Create the document's root node
     $envelopeRootNode = $this->_doc->createElement('s:Envelope');
     $this->setAttribute($envelopeRootNode, "xmlns:s", "http://www.w3.org/2003/05/soap-envelope");
     $this->setAttribute($envelopeRootNode, "xmlns:a", "http://www.w3.org/2005/08/addressing");
     $envelopeHeaderNode = $this->_doc->createElement('s:Header');
     $envelopeHeaderActionNode = $this->_doc->createElement('a:Action', 'urn:Iservice/IngestTvinciData');
     $this->setAttribute($envelopeHeaderActionNode, "s:mustUnderstand", "1");
     $envelopeHeaderNode->appendChild($envelopeHeaderActionNode);
     $envelopeBodyNode = $this->_doc->createElement('s:Body');
     $ingestTvinciDataNode = $this->_doc->createElement('IngestTvinciData');
     $tvinciDataRequestNode = $this->_doc->createElement('request');
     $this->setAttribute($tvinciDataRequestNode, "xmlns:i", "http://www.w3.org/2001/XMLSchema-instance");
     $tvinciDataRequestNode->appendChild($this->_doc->createElement('userName', $this->distributionProfile->username));
     $tvinciDataRequestNode->appendChild($this->_doc->createElement('passWord', $this->distributionProfile->password));
     $tvinciDataRequestNode->appendChild($this->_doc->createElement('schemaID', $this->distributionProfile->schemaId));
     // Attach the CDATA section
     $tvinciDataRequestNode->appendChild($data);
     $ingestTvinciDataNode->appendChild($tvinciDataRequestNode);
     $envelopeBodyNode->appendChild($ingestTvinciDataNode);
     $envelopeRootNode->appendChild($envelopeHeaderNode);
     $envelopeRootNode->appendChild($envelopeBodyNode);
     // Attach the root node to the document
     $this->_doc->appendChild($envelopeRootNode);
     return $this->getXml();
 }
Example #21
0
 private function getTextNode($value)
 {
     if (empty($value) || preg_match('/^[\\w\\s\\.\\-]+$/', $value, $match)) {
         return $this->dom->createTextNode($value);
     } else {
         return $this->dom->createCDATASection($value);
     }
 }
Example #22
0
 private function AppendCDATAChild($parent, $elementName, $contents)
 {
     $element = $this->domDoc->createElement($elementName);
     $cdata = $this->domDoc->createCDATASection($contents);
     $element->appendChild($cdata);
     $parent->appendChild($element);
     return $element;
 }
 private function createCDataNode(\DOMDocument $doc, $name, $content)
 {
     $node = $doc->createElement($name);
     if (null !== $content) {
         $node->appendChild($doc->createCDATASection($content));
     }
     return $node;
 }
Example #24
0
 /**
  *
  * New node with CDATA content
  * @param DOMNode $parentnode
  * @param string $namespace
  * @param string $name
  * @param string $value
  */
 public function append_new_element_ns_cdata(DOMNode &$parentnode, $namespace, $name, $value = null)
 {
     $newnode = $this->doc->createElementNS($namespace, $name);
     if (!is_null($value)) {
         $cdata = $this->doc->createCDATASection($value);
         $newnode->appendChild($cdata);
     }
     return $parentnode->appendChild($newnode);
 }
 public function createXmlElement(DOMDocument $xmlDoc, $nodeName)
 {
     if (!$xmlDoc instanceof DOMDocument) {
         throw new Exception('', self::ERROR_INVALID_PARAMETER);
     }
     $addrElem = $xmlDoc->createElement($nodeName);
     if ($this->type == null) {
         throw new Exception('Invalid address type', self::ERROR_INVALID_ADDRESS_TYPE);
     } else {
         if ($this->type != self::TYPE_COMPANY && $this->type != self::TYPE_PERSON) {
             throw new Exception('Invalid address type', self::ERROR_INVALID_ADDRESS_TYPE_VALUE);
         }
     }
     $xmlAttr = $xmlDoc->createAttribute('type');
     $xmlAttr->nodeValue = $this->type;
     $addrElem->appendChild($xmlAttr);
     if ($this->firstName != null) {
         $xmlElem = $xmlDoc->createElement('first_name');
         $xmlElem->appendChild($xmlDoc->createCDATASection(urlencode($this->firstName)));
         $addrElem->appendChild($xmlElem);
     }
     if ($this->lastName != null) {
         $xmlElem = $xmlDoc->createElement('last_name');
         $xmlElem->appendChild($xmlDoc->createCDATASection(urlencode($this->lastName)));
         $addrElem->appendChild($xmlElem);
     }
     if ($this->address != null) {
         $xmlElem = $xmlDoc->createElement('address');
         $xmlElem->appendChild($xmlDoc->createCDATASection(urlencode($this->address)));
         $addrElem->appendChild($xmlElem);
     }
     if ($this->email != null) {
         $xmlElem = $xmlDoc->createElement('email');
         $xmlElem->appendChild($xmlDoc->createCDATASection(urlencode($this->email)));
         $addrElem->appendChild($xmlElem);
     }
     if ($this->mobilePhone != null) {
         $xmlElem = $xmlDoc->createElement('mobile_phone');
         $xmlElem->appendChild($xmlDoc->createCDATASection(urlencode($this->mobilePhone)));
         $addrElem->appendChild($xmlElem);
     }
     return $addrElem;
 }
 /**
  * This method add a new child element with a cdata tag arround the content
  * @param string $sName
  * @param string $sValue
  * @return PayIntelligent_Util_SimpleXmlExtended
  */
 public function addCDataChild($sName, $sValue)
 {
     $oNodeOld = dom_import_simplexml($this);
     $oDom = new DOMDocument('1.0', 'utf-8');
     $oDataNode = $oDom->appendChild($oDom->createElement($sName));
     $oDataNode->appendChild($oDom->createCDATASection(utf8_encode($sValue)));
     $oNodeTarget = $oNodeOld->ownerDocument->importNode($oDataNode, true);
     $oNodeOld->appendChild($oNodeTarget);
     return simplexml_import_dom($oNodeTarget);
 }
 /**
  * Set tombstone comment
  *
  * @param  DOMDocument $dom
  * @param  DOMElement $root
  * @return void
  */
 protected function _setComment(DOMDocument $dom, DOMElement $root)
 {
     if (!$this->getDataContainer()->getComment()) {
         return;
     }
     $c = $dom->createElement('at:comment');
     $root->appendChild($c);
     $c->setAttribute('type', 'html');
     $cdata = $dom->createCDATASection($this->getDataContainer()->getComment());
     $c->appendChild($cdata);
 }
Example #28
0
 public function xmlEncode($params)
 {
     $doc = new \DOMDocument('1.0', 'utf-8');
     $xml = $doc->createElement('xml');
     foreach ($params as $key => $value) {
         $elem = $doc->createElement($key);
         $elem->appendChild($doc->createCDATASection($value));
         $xml->appendChild($elem);
     }
     return $doc->saveXML($xml);
 }
 protected function createMetadataItem($label, $value)
 {
     $datumItemElement = $this->_doc->createElement('datumItem');
     $labelElement = $this->_doc->createElement('label', $label);
     $cdata = $this->_doc->createCDATASection($value);
     $valueElement = $this->_doc->createElement('value');
     $valueElement->appendChild($cdata);
     $datumItemElement->appendChild($labelElement);
     $datumItemElement->appendChild($valueElement);
     return $datumItemElement;
 }
 /**
  * create CData child
  *
  * @param string $sName
  * @param string $sValue
  * @param bool   $utfMode
  *
  * @return SimpleXMLElement
  */
 public function addCDataChild($sName, $sValue)
 {
     $oNodeOld = dom_import_simplexml($this);
     $oNodeNew = new DOMNode();
     $oDom = new DOMDocument();
     $oDataNode = $oDom->appendChild($oDom->createElement($sName));
     $oDataNode->appendChild($oDom->createCDATASection($this->removeSpecialChars($sValue)));
     $oNodeTarget = $oNodeOld->ownerDocument->importNode($oDataNode, true);
     $oNodeOld->appendChild($oNodeTarget);
     return simplexml_import_dom($oNodeTarget);
 }