function props_to_xml() { # make the source xml # make doc and root $xml = new DomDocument(); $root = $xml->createElement('request'); $root->setAttribute('controller', params('controller')); $root->setAttribute('action', params('action')); $root = $xml->appendChild($root); # unpack the props into xml foreach ($this->props as $k => $v) { # if it will become xml, do that, otherwise make a dumb tag if (is_object($v) && method_exists($v, 'to_xml')) { $obj_xml = $v->to_xml(array(), true, true); $obj_xml = $xml->importNode($obj_xml->documentElement, true); $root->appendChild($obj_xml); } else { $node = $xml->createElement($k); if (strpos($v, '<') !== false || strpos($v, '>') !== false || strpos($v, '&') !== false) { $cdata = $xml->createCDATASection($v); } else { $cdata = $xml->createTextNode($v); } $node->appendChild($cdata); $node = $root->appendChild($node); } } return $xml; }
/** * Get the answer value as an xml element * @param \DomDocument $dom * @param \Jazzee\Entity\Answer $answer * @param integer $version * @return \DomElement */ public function getXmlAnswer(\DomDocument $dom, \Jazzee\Entity\Answer $answer, $version) { $eXml = $dom->createElement('element'); $eXml->setAttribute('elementId', $this->_element->getId()); $eXml->setAttribute('title', htmlentities($this->_element->getTitle(), ENT_COMPAT, 'utf-8')); $eXml->setAttribute('name', htmlentities($this->_element->getName(), ENT_COMPAT, 'utf-8')); $eXml->setAttribute('type', htmlentities($this->_element->getType()->getClass(), ENT_COMPAT, 'utf-8')); $eXml->setAttribute('weight', $this->_element->getWeight()); $elementsAnswers = $answer->getElementAnswersForElement($this->_element); switch ($version) { case 1: if ($value = $this->rawValue($answer)) { $eXml->appendChild($dom->createCDATASection(preg_replace('/[\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F]/', '', $value))); } break; case 2: $value = null; if (isset($elementsAnswers[0])) { $value = $this->_element->getItemById($elementsAnswers[0]->getEInteger())->getValue(); $name = $this->_element->getItemById($elementsAnswers[0]->getEInteger())->getName(); $id = $this->_element->getItemById($elementsAnswers[0]->getEInteger())->getId(); } if ($value) { $vXml = $dom->createElement('value'); $vXml->setAttribute('valueId', $id); $vXml->setAttribute('name', htmlentities($name, ENT_COMPAT, 'utf-8')); $vXml->appendChild($dom->createCDATASection(preg_replace('/[\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F]/', '', $value))); $eXml->appendChild($vXml); } break; } return $eXml; }
/** * Exports data to xml * * @param string $fileName * @return void */ public function exportToXML($fileName) { if (!$fileName) { $fileName = 'export-' . time() . '.xml'; } $doc = new DomDocument(); $doc->preserveWhiteSpace = FALSE; $doc->formatOutput = TRUE; $root = $doc->createElement('Table'); $root = $doc->appendChild($root); $fieldsMetaData = array(); $collection = $this->getCollection(); foreach ($collection as $row) { if (empty($fieldsMetaData)) { $row->load($row->getId()); $fieldsMetaData = $row->getTableMetaData(); } $rows = $doc->createElement('Row'); $rows = $root->appendChild($rows); foreach ($this->columns as $field) { if (isset($fieldsMetaData[$field['field']])) { $column = $doc->createElement('Column'); $column->setAttribute('name', $fieldsMetaData[$field['field']]['COLUMN_NAME']); $column->setAttribute('type', $fieldsMetaData[$field['field']]['DATA_TYPE']); $cData = $doc->createCDATASection(''); $cData->appendData($row->{$field['fieldMethod']}()); $column->appendChild($cData); $rows->appendChild($column); } } } header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $fileName . '"'); echo $doc->saveXML(); }
static function loadPageHTML($params) { $params = self::_extractParams($params); $return = ''; $return_first = !empty($params['first']) && $params['first'] == 'TRUE' ? TRUE : FALSE; $page = false; if (!empty($params['path']) && CI()->zone == 'website') { $load_params = array('path' => $params['path']); } else { if (!empty($params['id']) && CI()->zone == 'website') { $load_params = array('page_id' => $params['id']); } } $check_cache = !empty($params['cache']) && $params['cache'] == 'FALSE' ? FALSE : TRUE; $get_children = !empty($params['children']) && $params['children'] == 'FALSE' ? FALSE : TRUE; $page = CI()->loadPage($load_params, 'html', FALSE, $check_cache, $get_children); if ($page) { // Convert to XML $output_dom = new DomDocument('1.0', 'UTF-8'); $output = array2XML($page); $node = $output_dom->createCDATASection($output); $newnode = $output_dom->appendChild($node); return $output_dom; } }
/** * Transforms Message objects into XML * @return mixed */ protected function buildMessages() { $data = $this->dom->createElement('data'); foreach ($this->connector->getMessages() as $Message) { $element = $this->dom->createElement('message'); $sendername = $this->dom->createElement('sendername', $Message->getSenderName()); $text = $this->dom->createElement('text'); $recipients = $this->dom->createElement('recipients'); foreach ($Message->getRecipients() as $Recipient) { $msisdn = $this->dom->createElement('msisdn', $Recipient); $recipients->appendChild($msisdn); } $text->appendChild($this->dom->createCDATASection($Message->getContent())); $element->appendChild($sendername); $element->appendChild($text); $element->appendChild($recipients); $data->appendChild($element); } return $data; }
public function rssObservations() { global $objObservation, $objInstrument, $objLocation, $objPresentations, $objObserver, $baseURL, $objUtil; $dom = new DomDocument('1.0', 'US-ASCII'); // add root fcga -> The header $rssInfo = $dom->createElement('rss'); $rssDom = $dom->appendChild($rssInfo); $attr = $dom->createAttribute("version"); $rssInfo->appendChild($attr); $attrText = $dom->createTextNode("2.0"); $attr->appendChild($attrText); $attr = $dom->createAttribute("xmlns:content"); $rssInfo->appendChild($attr); $attrText = $dom->createTextNode("http://purl.org/rss/1.0/modules/content/"); $attr->appendChild($attrText); $attr = $dom->createAttribute("xmlns:dc"); $rssInfo->appendChild($attr); $attrText = $dom->createTextNode("http://purl.org/dc/elements/1.1/"); $attr->appendChild($attrText); $attr = $dom->createAttribute("xmlns:atom"); $rssInfo->appendChild($attr); $attrText = $dom->createTextNode("http://www.w3.org/2005/Atom"); $attr->appendChild($attrText); // add root - <channel> $channelDom = $rssDom->appendChild($dom->createElement('channel')); // add root - <channel> - <title> $titleDom = $channelDom->appendChild($dom->createElement('title')); $titleDom->appendChild($dom->createTextNode("DeepskyLog")); // add root - <channel> - <description> $descDom = $channelDom->appendChild($dom->createElement('description')); $descDom->appendChild($dom->createTextNode("DeepskyLog - visual deepsky and comets observations")); // add root - <channel> - <atom> $atomDom = $channelDom->appendChild($dom->createElement('atom:link')); $attr = $dom->createAttribute("href"); $atomDom->appendChild($attr); $attrText = $dom->createTextNode($baseURL . "observations.rss"); $attr->appendChild($attrText); $attr = $dom->createAttribute("rel"); $atomDom->appendChild($attr); $attrText = $dom->createTextNode("self"); $attr->appendChild($attrText); $attr = $dom->createAttribute("type"); $atomDom->appendChild($attr); $attrText = $dom->createTextNode("application/rss+xml"); $attr->appendChild($attrText); // add root - <channel> - <link> $linkDom = $channelDom->appendChild($dom->createElement('link')); $linkDom->appendChild($dom->createTextNode("http://www.deepskylog.org/")); $theDate = date('r'); // add root - <channel> - <link> $lbdDom = $channelDom->appendChild($dom->createElement('lastBuildDate')); $lbdDom->appendChild($dom->createTextNode($theDate)); // Get the new deepsky observations of the last month $theDate = date('Ymd', strtotime('-1 month')); $_GET['minyear'] = substr($theDate, 0, 4); $_GET['minmonth'] = substr($theDate, 4, 2); $_GET['minday'] = substr($theDate, 6, 2); $query = array("catalog" => '%', "mindate" => $objUtil->checkGetDate('minyear', 'minmonth', 'minday')); $result = $objObservation->getObservationFromQuery($query, 'A'); while (list($key, $value) = each($result)) { // add root - <channel> - <item> $itemDom = $channelDom->appendChild($dom->createElement('item')); $titleDom = $itemDom->appendChild($dom->createElement('title')); $titleDom->appendChild($dom->createTextNode($value['observername'] . " : " . $value['objectname'] . " with " . htmlspecialchars_decode($objInstrument->getInstrumentPropertyFromId($value['instrumentid'], 'name')) . " from " . $objLocation->getLocationPropertyFromId($objObservation->getDsObservationProperty($value['observationid'], 'locationid'), 'name'))); $linkDom = $itemDom->appendChild($dom->createElement('link')); $linkDom->appendChild($dom->createCDATASection($baseURL . "index.php?indexAction=detail_observation&observation=" . $value['observationid'] . "&QobsKey=0&dalm=D")); $descDom = $itemDom->appendChild($dom->createElement('description')); $descDom->appendChild($dom->createCDATASection($objPresentations->br2nl(utf8_encode($value['observationdescription'])))); $authorDom = $itemDom->appendChild($dom->createElement('dc:creator')); $authorDom->appendChild($dom->createCDATASection($value['observername'])); $guidDom = $itemDom->appendChild($dom->createElement('guid')); $guidDom->appendChild($dom->createTextNode("deepsky" . $value['observationid'])); $attr = $dom->createAttribute("isPermaLink"); $guidDom->appendChild($attr); $attrText = $dom->createTextNode("false"); $attr->appendChild($attrText); $pubDateDom = $itemDom->appendChild($dom->createElement('pubDate')); date_default_timezone_set('UTC'); $time = -999; $obs = $objObservation->getAllInfoDsObservation($value['observationid']); $time = $obs['time']; if ($time >= "0") { $hour = (int) ($time / 100); $minute = $time - 100 * $hour; } else { $hour = 0; $minute = 0; } $date = $value['observationdate']; $year = substr($date, 0, 4); $month = substr($date, 4, 2); $day = substr($date, 6, 2); $pubDateDom->appendChild($dom->createTextNode(date("r", mktime($hour, $minute, 0, $month, $day, $year)))); } include_once "cometobjects.php"; include_once "observers.php"; include_once "instruments.php"; include_once "locations.php"; include_once "cometobservations.php"; include_once "icqmethod.php"; include_once "icqreferencekey.php"; global $instDir, $objCometObject; $objects = new CometObjects(); $observer = new Observers(); $instrument = new Instruments(); $observation = new CometObservations(); $location = new Locations(); $util = $this; $ICQMETHODS = new ICQMETHOD(); $ICQREFERENCEKEYS = new ICQREFERENCEKEY(); $cometsResult = $observation->getObservationFromQuery($query); while (list($key, $value) = each($cometsResult)) { $objectname = $objCometObject->getName($observation->getObjectId($value)); // add root - <channel> - <item> $itemDom = $channelDom->appendChild($dom->createElement('item')); $title = htmlspecialchars_decode($objectname); // Location and instrument if ($observation->getLocationId($value) != 0 && $observation->getLocationId($value) != 1) { $title = $title . " from " . htmlspecialchars_decode($location->getLocationPropertyFromId($observation->getLocationId($value), 'name')); } if ($observation->getInstrumentId($value) != 0) { $title = $title . " with " . htmlspecialchars_decode($instrument->getInstrumentPropertyFromId($observation->getInstrumentId($value), 'name')); } $titleDom = $itemDom->appendChild($dom->createElement('title')); $titleDom->appendChild($dom->createTextNode($title)); $linkDom = $itemDom->appendChild($dom->createElement('link')); $linkDom->appendChild($dom->createCDATASection($baseURL . "index.php?indexAction=comets_detail_observation&observation=" . $value)); // Description $description = $observation->getDescription($value); if (strcmp($description, "") != 0) { $descDom = $itemDom->appendChild($dom->createElement('description')); $descDom->appendChild($dom->createCDATASection($objPresentations->br2nl(utf8_encode($description)))); } else { $descDom = $itemDom->appendChild($dom->createElement('description')); $descDom->appendChild($dom->createCDATASection("")); } $observerid = $observation->getObserverId($value); $observername = $observer->getObserverProperty($observerid, 'firstname') . " " . $observer->getObserverProperty($observerid, 'name'); $authorDom = $itemDom->appendChild($dom->createElement('dc:creator')); $authorDom->appendChild($dom->createCDATASection($observername)); $guidDom = $itemDom->appendChild($dom->createElement('guid')); $guidDom->appendChild($dom->createTextNode("comet" . $value)); $attr = $dom->createAttribute("isPermaLink"); $guidDom->appendChild($attr); $attrText = $dom->createTextNode("false"); $attr->appendChild($attrText); $pubDateDom = $itemDom->appendChild($dom->createElement('pubDate')); date_default_timezone_set('UTC'); $date = sscanf($observation->getLocalDate($value), "%4d%2d%2d"); $time = $observation->getLocalTime($value); $hour = (int) ($time / 100); $minute = $time - $hour * 100; $pubDateDom->appendChild($dom->createTextNode(date("r", mktime($hour, $minute, 0, $date[1], $date[2], $date[0])))); } // generate xml $dom->formatOutput = true; // set the formatOutput attribute of // domDocument to true // save XML as string or file $test1 = $dom->saveXML(); // put string in test1 print $test1; }
private function createRss() { $dom = new DomDocument("1.0", "utf-8"); $dom->formatOutput = true; $dom->preserveWhiteSpace = false; //create $dom and done format $rss = $dom->createElement("rss"); $dom->appendChild($rss); //create rss $version = $dom->createAttribute("version"); $version->value = '2.0'; //choose version $rss->appendChild($version); $chanel = $dom->createElement("chanel"); $title = $dom->createElement("title", self::RSS_TITLE); $link = $dom->createElement("link", self::RSS_LINK); $chanel->appendChild($title); $chanel->appendChild($link); $chanel->appendChild($link); $rss->appendChild($chanel); $lenta = $this->getNews(); if (!$lenta) { return false; } foreach ($lenta as $news) { $item = $dom->createElement("item"); $title = $dom->createElement("title", $news["title"]); $category = $dom->createElement("category", $news["category"]); //обёртка над description $desc = $dom->createElement("description"); $cdata = $dom->createCDATASection($news["description"]); $desc->appendChild($cdata); $link = $dom->createElement("link", "#"); $dt = date("r", $news["datetime"]); $pubDate = $dom->createElement("pubDate", $dt); $item->appendChild($title); $item->appendChild($link); $item->appendChild($desc); $item->appendChild($pubDate); $item->appendChild($category); $chanel->appendChild($item); } $dom->save(self::RSS_NAME); }
/** * General manipulate wrapper method. * * @param string $input The XML fragment to be manipulated. We are only * interested in the <extension><CSVData> fragment added in the * MIK mappings file. * * @return string * One of the manipulated XML fragment, the original input XML if the * input is not the fragment we are interested in, or an empty string, * which as the effect of removing the empty <extension><CSVData> * fragement from our MODS (if there was an error, for example, we don't * want empty extension elements in our MODS documents). */ public function manipulate($input) { $dom = new \DomDocument(); $dom->loadxml($input, LIBXML_NSCLEAN); // Test to see if the current fragment is <extension><CSVData>. $xpath = new \DOMXPath($dom); $csvdatas = $xpath->query("//extension/CSVData"); // There should only be one <CSVData> fragment in the incoming // XML. If there is 0 or more than 1, return the original. if ($csvdatas->length === 1) { $csvdata = $csvdatas->item(0); $csvid = $dom->createElement('id_in_csv', $this->record_key); $csvdata->appendChild($csvid); $timestamp = date("Y-m-d H:i:s"); // Add the <CSVRecord> element. $csvrecord = $dom->createElement('CSVRecord'); $now = $dom->createAttribute('timestamp'); $now->value = $timestamp; $csvrecord->appendChild($now); $mimetype = $dom->createAttribute('mimetype'); $mimetype->value = 'application/json'; $csvrecord->appendChild($mimetype); try { $metadata_path = $this->settings['FETCHER']['temp_directory'] . DIRECTORY_SEPARATOR . $this->record_key . '.metadata'; $metadata_contents = file_get_contents($metadata_path); $metadata_contents = unserialize($metadata_contents); $metadata_contents = json_encode($metadata_contents); } catch (Exception $e) { $message = "Problem creating <CSVRecord> element for object " . $this->record_key . ":" . $e->getMessage(); $this->log->addInfo("AddCsvData", array('CSV metadata warning' => $message)); return ''; } // If the metadata contains the CDATA end delimiter, log and return. if (preg_match('/\\]\\]>/', $metadata_contents)) { $message = "CSV metadata for object " . $this->record_key . ' contains the CDATA end delimiter ]]>'; $this->log->addInfo("AddCsvData", array('CSV metadata warning' => $message)); return ''; } // If we've made it this far, add the metadata to <CcvData> as // CDATA and return the modified XML fragment. if (strlen($metadata_contents)) { $cdata = $dom->createCDATASection($metadata_contents); $csvrecord->appendChild($cdata); $csvdata->appendChild($csvrecord); } return $dom->saveXML($dom->documentElement); } else { // If current fragment is not <extension><CSVData>, return it // unmodified. return $input; } }
protected function readDataBlock() { $v4b43b0aee35624cd95b910189b3dc231 = new XMLReader(); $v4b43b0aee35624cd95b910189b3dc231->open($this->file_path); $v2245023265ae4cf87d02c8b6ba991139 = mainConfiguration::getInstance(); $vf7c163939469a0b7becb4e4e6a94efac = $v2245023265ae4cf87d02c8b6ba991139->includeParam('system.kernel') . 'subsystems/import/schemes/' . $this->type . '.xsd'; if (is_file($vf7c163939469a0b7becb4e4e6a94efac)) { $v4b43b0aee35624cd95b910189b3dc231->setSchema($vf7c163939469a0b7becb4e4e6a94efac); } $v9a09b4dfda82e3e665e31092d1c3ec8d = new DomDocument("1.0", "utf-8"); $v07214c6750d983a32e0a33da225c4efd = array('umidump/registry/key', 'umidump/files/file', 'umidump/directories/directory', 'umidump/langs/lang', 'umidump/domains/domain', 'umidump/templates/template', 'umidump/datatypes/datatype', 'umidump/types/type', 'umidump/pages/page', 'umidump/objects/object', 'umidump/relations/relation', 'umidump/options/entity', 'umidump/restrictions/restriction', 'umidump/permissions/permission', 'umidump/hierarchy/relation'); $v95723b5e620e47cf613462b9f293282a = 0; $v4757fe07fd492a8be0ea6a760d683d6e = 0; $v5f0b6ebc4bea10285ba2b8a6ce78b863 = $v9a09b4dfda82e3e665e31092d1c3ec8d; $v7aa28ed115707345d0274032757e8991 = $v4b43b0aee35624cd95b910189b3dc231->read(); while ($v7aa28ed115707345d0274032757e8991 && $v95723b5e620e47cf613462b9f293282a <= $this->block_size) { switch ($v4b43b0aee35624cd95b910189b3dc231->nodeType) { case XMLReader::ELEMENT: $v3f02ab347aeca12e013036ce82046c38 = $this->__getNodePath($v5f0b6ebc4bea10285ba2b8a6ce78b863); if (in_array($v3f02ab347aeca12e013036ce82046c38 . "/" . $v4b43b0aee35624cd95b910189b3dc231->name, $v07214c6750d983a32e0a33da225c4efd)) { if ($v4757fe07fd492a8be0ea6a760d683d6e++ < $this->offset) { $v7aa28ed115707345d0274032757e8991 = $v4b43b0aee35624cd95b910189b3dc231->next(); continue 2; } if ($v95723b5e620e47cf613462b9f293282a + 1 > $this->block_size) { break 2; } $v95723b5e620e47cf613462b9f293282a++; } $v65c10911d8b8591219a21ebacf46da01 = $v9a09b4dfda82e3e665e31092d1c3ec8d->createElement($v4b43b0aee35624cd95b910189b3dc231->name, $v4b43b0aee35624cd95b910189b3dc231->value); $v5f0b6ebc4bea10285ba2b8a6ce78b863->appendChild($v65c10911d8b8591219a21ebacf46da01); if (!$v4b43b0aee35624cd95b910189b3dc231->isEmptyElement) { $v5f0b6ebc4bea10285ba2b8a6ce78b863 = $v65c10911d8b8591219a21ebacf46da01; } if ($v4b43b0aee35624cd95b910189b3dc231->attributeCount) { while ($v4b43b0aee35624cd95b910189b3dc231->moveToNextAttribute()) { $v815be97df65d6c4b510cd07189c5347a = $v9a09b4dfda82e3e665e31092d1c3ec8d->createAttribute($v4b43b0aee35624cd95b910189b3dc231->name); $v815be97df65d6c4b510cd07189c5347a->appendChild($v9a09b4dfda82e3e665e31092d1c3ec8d->createTextNode($v4b43b0aee35624cd95b910189b3dc231->value)); $v65c10911d8b8591219a21ebacf46da01->appendChild($v815be97df65d6c4b510cd07189c5347a); } } break; case XMLReader::END_ELEMENT: $v5f0b6ebc4bea10285ba2b8a6ce78b863 = $v5f0b6ebc4bea10285ba2b8a6ce78b863->parentNode; break; case XMLReader::ATTRIBUTE: $v815be97df65d6c4b510cd07189c5347a = $v9a09b4dfda82e3e665e31092d1c3ec8d->createAttribute($v4b43b0aee35624cd95b910189b3dc231->name); $v815be97df65d6c4b510cd07189c5347a->appendChild($v9a09b4dfda82e3e665e31092d1c3ec8d->createTextNode($v4b43b0aee35624cd95b910189b3dc231->value)); $v5f0b6ebc4bea10285ba2b8a6ce78b863->appendChild($v815be97df65d6c4b510cd07189c5347a); break; case XMLReader::TEXT: $vc7824f3d4d5f7b2f22d034758c1e9454 = $v9a09b4dfda82e3e665e31092d1c3ec8d->createTextNode($v4b43b0aee35624cd95b910189b3dc231->value); $v5f0b6ebc4bea10285ba2b8a6ce78b863->appendChild($vc7824f3d4d5f7b2f22d034758c1e9454); break; case XMLReader::CDATA: $vd9ef6bda8fb69f1c7e277bd1c2cd21d1 = $v9a09b4dfda82e3e665e31092d1c3ec8d->createCDATASection($v4b43b0aee35624cd95b910189b3dc231->value); $v5f0b6ebc4bea10285ba2b8a6ce78b863->appendChild($vd9ef6bda8fb69f1c7e277bd1c2cd21d1); break; case XMLReader::NONE: default: } $v7aa28ed115707345d0274032757e8991 = $v4b43b0aee35624cd95b910189b3dc231->read(); } $this->offset += $v95723b5e620e47cf613462b9f293282a; if (!$v7aa28ed115707345d0274032757e8991) { $this->complete = true; } return $v9a09b4dfda82e3e665e31092d1c3ec8d; }
/** * Implemet the pages/create ane emails/create methods to ceate a new web * page test or a new email test. * * @param string $test_type Type of the test (TYPE_PAGE||TYPE_EMAIL) * @param array $params Parameters of the test * @return Litmus_Test */ public static function create($test_type, $params) { $dom = new DomDocument('1.0', null); $root = $dom->createElement('test_set'); $dom->appendChild($root); // application element $applications = $dom->createElement('applications'); $type = $dom->createAttribute('type'); $type->appendChild($dom->createTextNode('array')); $applications->appendChild($type); $root->appendChild($applications); if (isset($params['applications'])) { foreach ($params['applications'] as $app) { $app_node = $dom->createElement('application'); $code_node = $dom->createElement('code', $app); $app_node->appendChild($code_node); $applications->appendChild($app_node); } } // url node if (isset($params['url'])) { $node = $dom->createElement('url', $params['url']); $root->appendChild($node); } // save defaults node $node = $dom->createElement('save_defaults', isset($params['save_defaults']) && $params['save_defaults'] ? 'true' : 'false'); $root->appendChild($node); // use defaults node $node = $dom->createElement('use_defaults', isset($params['use_defaults']) && $params['use_defaults'] ? 'true' : 'false'); $root->appendChild($node); if (isset($params['email_source'])) { $email_node = $dom->createElement('email_source'); $root->appendChild($email_node); $node = $dom->createElement('body'); $data = $dom->createCDATASection($params['email_source']['body']); $node->appendChild($data); $email_node->appendChild($node); $node = $dom->createElement('subject', $params['email_source']['subject']); $email_node->appendChild($node); } $request = $dom->saveXML(); $rc = Litmus_RESTful_Client::singleton(); $res = $rc->post($test_type . '.xml', $request); $test = Litmus_Test::load($res); return $test; }
protected function produceAtom($feedArray) { // Atom 1.0 $doc = new DomDocument('1.0', 'utf-8'); $feed = $doc->createElement('feed'); $feed->setAttribute('xmlns:itunes', 'http://www.itunes.com/dtds/podcast-1.0.dtd'); $feed->setAttribute('xmlns', 'http://www.w3.org/2005/Atom'); $feed->setAttribute('xml:lang', $feedArray['language']); $doc->appendChild($feed); $title = $doc->createElement('title', $feedArray['title']); $title->setAttribute('type', 'text'); $subtitle = $doc->createElement('subtitle', $feedArray['description']); $subtitle->setAttribute('type', 'text'); $updated = $doc->createElement('updated', date('Y-m-d\\TH:i:sP')); $generator = $doc->createElement('generator', ProjectConfiguration::getApplicationName() . ' Feed Module'); $link_alternate = $doc->createElement('link'); $link_alternate->setAttribute('rel', 'alternate'); $link_alternate->setAttribute('type', 'text/html'); $link_alternate->setAttribute('href', $feedArray['link']); $link_self = $doc->createElement('link'); $link_self->setAttribute('rel', 'self'); $link_self->setAttribute('type', 'application/atom+xml'); $link_self->setAttribute('href', $feedArray['atom_link']); $id = $doc->createElement('id', $feedArray['link']); $author = $doc->createElement('author'); $a_name = $doc->createElement('name', ProjectConfiguration::getApplicationName()); $a_email = $doc->createElement('email', ProjectConfiguration::getApplicationEmailAddress()); $a_uri = $doc->createElement('uri', $this->getController()->genUrl('@homepage', true)); $author->appendChild($a_name); $author->appendChild($a_email); $author->appendChild($a_uri); $feed->appendChild($title); $feed->appendChild($subtitle); $feed->appendChild($updated); $feed->appendChild($generator); $feed->appendChild($link_alternate); $feed->appendChild($link_self); $feed->appendChild($id); $feed->appendChild($author); $itunes_explicit = $doc->createElement('itunes:explicit', $feedArray["is_nsfw"]); $itunes_summary = $doc->createElement('itunes:summary', substr($feedArray['description'], 0, 3999)); $itunes_category = $doc->createElement('itunes:category'); $itunes_category->setAttribute('text', 'Technology'); $itunes_subcategory = $doc->createElement('itunes:category'); $itunes_subcategory->setAttribute('text', 'Podcasting'); $itunes_category->appendChild($itunes_subcategory); // Including the itunes:owner messes with the feed by overriding the title in iTunes. $feed->appendChild($itunes_explicit); $feed->appendChild($itunes_summary); $feed->appendChild($itunes_category); foreach ($feedArray['entries'] as $entry) { $fentry = $doc->createElement('entry'); //$fentry->setAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); $e_title = $doc->createElement('title'); $e_title->setAttribute('type', 'html'); $cdata_title = $doc->createCDATASection($entry['title']); $e_title->appendChild($cdata_title); $thumbnail_tag = $entry['thumbnail'] ? '<p><img src="' . $entry['thumbnail'] . '"/></p>' : ''; $e_summary = $doc->createElement('summary'); $e_summary->setAttribute('type', 'html'); $cdata_summary = $doc->createCDATASection($thumbnail_tag . substr($entry['description'], 0, 500)); $e_summary->appendChild($cdata_summary); $e_published = $doc->createElement('published', date('Y-m-d\\TH:i:sP', $entry['released'])); $e_updated = $doc->createElement('updated', date('Y-m-d\\TH:i:sP', $entry['modified'] > $entry['released'] ? $entry['modified'] : $entry['released'])); $e_link = $doc->createElement('link'); $e_link->setAttribute('rel', 'alternate'); $e_link->setAttribute('type', 'text/html'); $e_link->setAttribute('href', $entry['link']); $e_id = $doc->createElement('id', $entry['link']); $e_author = $doc->createElement('author'); $ea_name = $doc->createElement('name', $entry['author']['name']); $e_author->appendChild($ea_name); $e_enclosure = $doc->createElement('link'); $e_enclosure->setAttribute('rel', 'enclosure'); $audio_info = $this->getRemoteInfo($entry['audio_location']); $e_enclosure->setAttribute('type', $audio_info['type']); $e_enclosure->setAttribute('href', $entry['audio_location']); $e_enclosure->setAttribute('length', $audio_info['length']); $e_enclosure->setAttribute('title', 'Audio'); $e_content = $doc->createElement('content'); //$e_content->setAttribute('xmlns:xhtml', // 'http://www.w3.org/1999/xhtml'); $e_content->setAttribute('type', 'xhtml'); $fragment = $doc->createDocumentFragment(); $fragment->appendXML($thumbnail_tag . $entry['content']); $e_div = $doc->createElement('div'); $e_div->setAttribute('xmlns', 'http://www.w3.org/1999/xhtml'); $e_div->appendChild($fragment); $e_content->appendChild($e_div); if ($entry['reddit_post_url']) { $e_comments = $doc->createElement('link'); $e_comments->setAttribute('rel', 'replies'); $e_comments->setAttribute('type', 'text/html'); $e_comments->setAttribute('href', $entry['reddit_post_url']); } $fentry->appendChild($e_title); $fentry->appendChild($e_summary); $fentry->appendChild($e_published); $fentry->appendChild($e_updated); $fentry->appendChild($e_link); $fentry->appendChild($e_id); $fentry->appendChild($e_author); $fentry->appendChild($e_enclosure); $fentry->appendChild($e_content); $i_itunes_author = $doc->createElement('itunes:author', $entry['author']['name']); $i_itunes_summary = $doc->createElement('itunes:summary', substr(strip_tags($entry['description']), 0, 3999)); $i_itunes_explicit = $doc->createElement('itunes:explicit', $entry['is_nsfw']); $fentry->appendChild($i_itunes_author); $fentry->appendChild($i_itunes_summary); $fentry->appendChild($i_itunes_explicit); $feed->appendChild($fentry); } $doc->formatOutput = true; $doc->preserveWhitespace = false; return $doc->saveXML(); }
/** * generate rss feed output * * @param array $items post item array * @return void */ function output_rss($posts, $cache = false, $file = NULL) { global $config; if (!is_array($posts)) { die('no posts ...'); } $lastmod = strtotime($posts[0]['date']); // http headers header('Content-type: application/xml; charset=utf-8'); // set mime ... application/rss+xml header('Cache-Control: max-age=300, must-revalidate'); // cache control 5 mins header('Last-Modified: ' . gmdate('D, j M Y H:i:s T', $lastmod)); //D, j M Y H:i:s T header('Expires: ' . gmdate('D, j M Y H:i:s T', time() + 300)); // conditional get ... $ifmod = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] === gmdate('D, j M Y H:i:s T', $lastmod) : FALSE; if (FALSE !== $ifmod) { $config['DEBUG'] && error_log('[DEBUG] 304 NOT MODIFIED :)'); header('HTTP/1.0 304 Not Modified'); exit; } // build rss using dom $dom = new DomDocument(); $dom->formatOutput = TRUE; $dom->encoding = 'utf-8'; $rss = $dom->createElement('rss'); $rss->setAttribute('version', '2.0'); $rss->setAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom'); // atom for self $rss->setAttribute('xmlns:media', 'http://search.yahoo.com/mrss/'); //xmlns:media="http://search.yahoo.com/mrss/" $dom->appendChild($rss); $channel = $dom->createElement('channel'); $rss->appendChild($channel); // set up feed properties $title = $dom->createElement('title', 'My Tumblr Dashboard Feed'); $channel->appendChild($title); $link = $dom->createElement('link', 'http://tumblr.com/dashboard'); $channel->appendChild($link); $description = $dom->createElement('description', 'My tumblr dashboard feed'); $channel->appendChild($description); $language = $dom->createElement('language', 'en-us'); $channel->appendChild($language); $pubDate = $dom->createElement('pubDate', $posts[0]['date']); $channel->appendChild($pubDate); $lastBuild = $dom->createElement('lastBuildDate', date(DATE_RSS)); $channel->appendChild($lastBuild); $docs = $dom->createElement('docs', 'http://blogs.law.harvard.edu/tech/rss'); $channel->appendChild($docs); $generator = $dom->createElement('generator', 'Tumbler API'); $channel->appendChild($generator); $managingEditor = $dom->createElement('managingEditor', 'editor@example.com (editor)'); $channel->appendChild($managingEditor); $webMaster = $dom->createElement('webMaster', 'webmaster@example.com (webmaster)'); $channel->appendChild($webMaster); $self = $dom->createElement('atom:link'); $self->setAttribute('href', 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); $self->setAttribute('rel', 'self'); $self->setAttribute('type', 'application/rss+xml'); $channel->appendChild($self); // add items foreach ($posts as $post) { $item = $dom->createElement('item'); $link = $dom->createElement('link', $post['link']); // $link->appendChild( $dom->createTextNode( $item['link'] ) ); $item->appendChild($link); $title = $dom->createElement('title', $post['title']); $item->appendChild($title); $description = $dom->createElement('description'); // put description in cdata to avoid breakage $cdata = $dom->createCDATASection($post['description']); $description->appendChild($cdata); $item->appendChild($description); $pubDate = $dom->createElement('pubDate', $post['date']); $item->appendChild($pubDate); $guid = $dom->createElement('guid', $post['link']); $item->appendChild($guid); // if enclosure ... if (isset($post['enclosure'])) { //<enclosure url="http://www.webmonkey.com/monkeyrock.mpg" length="2471632" type="video/mpeg"/> $enclosure = $dom->createElement('enclosure'); $enclosure->setAttribute('url', $post['enclosure']['url']); $enclosure->setAttribute('length', '1024'); // this is required but doesn't need to be accurate $enclosure->setAttribute('type', $post['enclosure']['type']); // valid mime type $item->appendChild($enclosure); // media rss? } $channel->appendChild($item); } // cache output if ($config['cache']['output'] == TRUE && is_writable($config['cache']['dir'])) { $dom->save($config['cache']['dir'] . DIRECTORY_SEPARATOR . $config['cache']['output_file']); } // send output to browser echo $dom->saveXML(); }
/** * Creates a language description file for TAO using the RDF-XML language. * * @access public * @author Jerome Bogaerts <*****@*****.**> * @param string code string code The language code e.g. fr-FR. * @param string label string label The language label e.g. French in english. * @return DomDocument */ public static function createLanguageDescription($code, $label) { $returnValue = null; $languageType = CLASS_LANGUAGES; $languagePrefix = 'http://www.tao.lu/Ontologies/TAO.rdf#Lang'; $rdfNs = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; $rdfsNs = 'http://www.w3.org/2000/01/rdf-schema#'; $xmlNs = 'http://www.w3.org/XML/1998/namespace'; $xmlnsNs = 'http://www.w3.org/2000/xmlns/'; $base = 'http://www.tao.lu/Ontologies/TAO.rdf#'; $doc = new DomDocument('1.0', 'UTF-8'); $doc->formatOutput = true; $rdfNode = $doc->createElementNS($rdfNs, 'rdf:RDF'); $rdfNode->setAttributeNS($xmlNs, 'xml:base', $base); $doc->appendChild($rdfNode); $descriptionNode = $doc->createElementNS($rdfNs, 'rdf:Description'); $descriptionNode->setAttributeNS($rdfNs, 'rdf:about', $languagePrefix . $code); $rdfNode->appendChild($descriptionNode); $typeNode = $doc->createElementNS($rdfNs, 'rdf:type'); $typeNode->setAttributeNS($rdfNs, 'rdf:resource', $languageType); $descriptionNode->appendChild($typeNode); $labelNode = $doc->createElementNS($rdfsNs, 'rdfs:label'); $labelNode->setAttributeNS($xmlNs, 'xml:lang', DEFAULT_LANG); $labelNode->appendChild($doc->createCDATASection($label)); $descriptionNode->appendChild($labelNode); $valueNode = $doc->createElementNS($rdfNs, 'rdf:value'); $valueNode->appendChild($doc->createCDATASection($code)); $descriptionNode->appendChild($valueNode); $guiUsageNode = $doc->createElementNS($base, 'tao:languageUsages'); $guiUsageNode->setAttributeNs($rdfNs, 'rdf:resource', INSTANCE_LANGUAGE_USAGE_GUI); $descriptionNode->appendChild($guiUsageNode); $dataUsageNode = $doc->createElementNS($base, 'tao:languageUsages'); $dataUsageNode->setAttributeNs($rdfNs, 'rdf:resource', INSTANCE_LANGUAGE_USAGE_DATA); $descriptionNode->appendChild($dataUsageNode); $dataUsageNode = $doc->createElementNS($base, 'tao:LanguageOrientation'); $dataUsageNode->setAttributeNs($rdfNs, 'rdf:resource', INSTANCE_ORIENTATION_LTR); $descriptionNode->appendChild($dataUsageNode); $returnValue = $doc; return $returnValue; }
} if (!$server->isAuthorized()) { Logger::error('main', '(webservices/applications/webapps) Server is not authorized (error_code: 2)'); webservices_return_error(2, 'Server is not authorized'); } header('Content-Type: text/xml; charset=utf-8'); $dom = new DomDocument('1.0', 'utf-8'); $node = $dom->createElement('webapps'); $applicationDB = ApplicationDB::getInstance(); $webapp_application_DB = WebAppConfDB::getInstance(); $applications = $applicationDB->getList('webapp'); if (is_array($applications)) { foreach ($applications as $app) { $app_node = $dom->createElement('webapp'); $app_node->setAttribute('id', $app->getAttribute('id')); $app_node->setAttribute('name', $app->getAttribute('name')); $app_node->setAttribute('description', $app->getAttribute('description')); $app_node->setAttribute('revision', $app->getAttribute('revision')); $webapp_configuration_object = $webapp_application_DB->search($app->getAttribute('id')); if ($webapp_configuration_object != NULL) { $configuration = $webapp_configuration_object->getUpdatedConfguration(); $config_node = $dom->createElement('configuration'); $config_node->appendChild($dom->createCDATASection($configuration)); $app_node->appendChild($config_node); } $node->appendChild($app_node); } } $dom->appendChild($node); echo $dom->saveXML(); exit(0);
/** * appendNodeIfValue is a helper function for buildTransactionNodes, which * is used by buildRequestXML to construct an XML transaction. * This function will append an XML node to the transaction being built via * the passed-in parent node, only if the current node would have a * non-empty value. * @param string $value The GATEWAY's field name for the current node. * @param DOMElement $node The parent node this node will be contained in, if it * is determined to have a non-empty value. * @param bool $js Probably cruft at this point. This is connected to the * function buildTransactionFormat. */ protected function appendNodeIfValue($value, &$node, $js = false) { $nodevalue = $this->getTransactionSpecificValue($value, $js); if ($nodevalue !== '' && $nodevalue !== false) { $temp = $this->xmlDoc->createElement($value); $data = null; if (in_array($value, $this->cdata)) { $data = $this->xmlDoc->createCDATASection($nodevalue); } else { $data = $this->xmlDoc->createTextNode($nodevalue); } $temp->appendChild($data); $node->appendChild($temp); } }
/** * for each file that is associated to the given document the fulltext and * path information are attached to the xml representation of the document model * * @param DomDocument $modelXml * @param Opus_File $files * @param $docId * @return void */ private function attachFulltextToXml($modelXml, $files, $docId) { $docXml = $modelXml->getElementsByTagName('Opus_Document')->item(0); if (is_null($docXml)) { $this->log->warn('An error occurred while attaching fulltext information to the xml for document with id ' . $docId); return; } // only consider files which are visible in frontdoor $files = array_filter($files, function ($file) { return $file->getVisibleInFrontdoor() === '1'; }); if (count($files) == 0) { $docXml->appendChild($modelXml->createElement('Has_Fulltext', 'false')); return; } $docXml->appendChild($modelXml->createElement('Has_Fulltext', 'true')); foreach ($files as $file) { $fulltext = ''; try { $this->totalFileCount++; $fulltext = trim(iconv("UTF-8", "UTF-8//IGNORE", $this->getFileContent($file))); } catch (Opus_SolrSearch_Index_Exception $e) { $this->errorFileCount++; $this->log->err('An error occurred while getting fulltext data for document with id ' . $docId . ': ' . $e->getMessage()); } if ($fulltext != '') { $element = $modelXml->createElement('Fulltext_Index'); $element->appendChild($modelXml->createCDATASection($fulltext)); $docXml->appendChild($element); $element = $modelXml->createElement('Fulltext_ID_Success'); $element->appendChild($modelXml->createTextNode($this->getFulltextHash($file))); $docXml->appendChild($element); } else { $element = $modelXml->createElement('Fulltext_ID_Failure'); $element->appendChild($modelXml->createTextNode($this->getFulltextHash($file))); $docXml->appendChild($element); } } }
/** * Création des fichiers .xsl & .xml pour une fonction ou une tâche donnée. * * @param EiEnvironnementEiProfil $environnement Environnement sur lequel se base la tâche et/ou la fonction. * @param EiProfil $profil Profil utilisé. * @param array $commands Liste des séquences/fonctions à inclure. * @param EiTache|EiFunction $objet Fonction ou Tâche à exporter. */ public static function creerXSL(sfWebRequest $request, EiProjet $ei_project, EiUser $ei_user, EiProfil $profil = null, $commands = null) { //Récupération des paramètres de profil $profileParams = $profil->getParamsWithName($ei_user); /*************************************/ /***** Définition du XSL *****/ /*************************************/ // On définit le document. $dom = new DomDocument("1.0", "UTF-8"); $dom->formatOutput = true; // On définit les spécificités xsl. //-> Feuille de Style $css = $dom->createElement('xsl:stylesheet'); $css->setAttribute("xmlns:xsl", "http://www.w3.org/1999/XSL/Transform"); $css->setAttribute("version", "1.0"); $dom->appendChild($css); //-> Fichier de sortie $ps = $dom->createElement('xsl:preserve-space'); $ps->setAttribute("elements", "xsl:text"); $css->appendChild($ps); //-> Fichier de sortie $pi = $dom->createElement('xsl:output'); $pi->setAttribute("method", "xml"); $css->appendChild($pi); //-> Template à matcher. $tpl = $dom->createElement('xsl:template'); $tpl->setAttribute("match", "/"); $css = $css->appendChild($tpl); // On définit le jeu de test. $test = $dom->createElement("TestCase"); $test->setAttribute("seleniumIDEVersion", sfConfig::get("app_xml_seleniumIDEVersion")); if ($profil != null) { $test->setAttribute("baseURL", $profil->getBaseUrl()); } else { $test->setAttribute("baseURL", "default"); } // Puis on l'ajoute. $tpl = $tpl->appendChild($test); /************************************************ */ /***** Séquences/Fonctions/Commandes **** */ /************************************************ */ if ($commands != null) { foreach ($commands as $index => $command) { /******************************************** */ /***** Chargement des paramètres **** */ /******************************************** */ // en créant la racine selense. $o = $dom->createElement("selenese"); // Puis ses trois noeuds: commande, target, value. $cmd = $o->appendChild($dom->createElement("command")); $texte = $cmd->appendChild($dom->createTextNode($command->getName())); // Cible dynamique/statique $cible = $o->appendChild($dom->createElement("target")); $pattern = "#(?<!\\#)\\#\\{[\\w./]*}#"; /* On commence par interpréter tous les paramètres de profil sur la cible de la commande */ //$ch1=self::parseAndExtractProfileParamsValue($command->getCommandTarget(), $profileParams); $ch1 = self::replaceProfileParamWithValue($command->getCommandTarget(), $profileParams); $nbMatched = preg_match_all($pattern, $ch1, $matches); if (isset($matches) && $nbMatched > 0) { $toReplace = array(); //$ch1 = $command->getCommandTarget(); // pour chaque élément qui a matché le pattern foreach ($matches[0] as $m => $param) { //on protège notre expression afin que celle-ci ne soit pas considérer comme un pattern de regex $matches[0][$m] = '#\\' . preg_quote($param) . '#'; //puis l'on créer la chaine de remplacement correspondante $dompar = $dom->createElement("xsl:value-of"); $dompar->setAttribute("select", "user/fonction-" . $command->getFunctionId() . "_" . $command->getFunctionRef() . "/parameter[@name='" . substr($param, 2, -1) . "']/value"); //On récupère la sous chaine de $ch à partir de $param $sous_chaine_restante = strstr($ch1, $param); $cible->appendChild($dom->createCDATASection(substr($ch1, 0, stripos($ch1, $sous_chaine_restante)))); //stripos recherche la première occurence de $sous_chaine_restante dans $ch $cible->appendChild($dompar); //on ajoute la section <xsl:value-of> au CDATA //On extrait à la sous chaine restante le paramètre variable trouvé $ch1 = substr($sous_chaine_restante, strlen($param)); } /* Si c'est le dernier paramètre à interpreter ou si on trouvé aucun paramètre à interpreter alors on ajoute le reste de texte */ $cible->appendChild($dom->createCDATASection($ch1)); } else { $cible->appendChild($dom->createCDATASection($ch1)); } //Interprétation de la valeur de la commande $valeur = $o->appendChild($dom->createElement("value")); /* On commence par interpréter tous les paramètres de profil sur la valeur de la commande */ //$ch2=self::parseAndExtractProfileParamsValue($command->getCommandValue(), $profileParams); $ch2 = self::replaceProfileParamWithValue($command->getCommandValue(), $profileParams); $nbMatched = preg_match_all($pattern, $ch2, $matches); if (isset($matches) && $nbMatched > 0) { $toReplace = array(); //$ch = $command->getCommandValue(); // pour chaque élément qui a matché le pattern foreach ($matches[0] as $m => $param) { //on protège notre expression afin que celle-ci ne soit pas considérer comme un pattern de regex $matches[0][$m] = '#\\' . preg_quote($param) . '#'; //puis l'on créer la chaine de remplacement correspondante $dompar = $dom->createElement("xsl:value-of"); $dompar->setAttribute("select", "user/fonction-" . $command->getFunctionId() . "_" . $command->getFunctionRef() . "/parameter[@name='" . substr($param, 2, -1) . "']/value"); //$toReplace[$m]=$dompar; //Méthode 2 $sous_chaine_restante = strstr($ch2, $param); $sous_chaine_restante_debut = substr($ch2, 0, stripos($ch2, $sous_chaine_restante)); // Si que des caractères vides, on place cela dans une balise texte. if (preg_match("/^([[:space:]]+)\$/", $sous_chaine_restante_debut)) { $valeur->appendChild($dom->createElement("xsl:text", "" . $sous_chaine_restante_debut . "")); } else { $valeur->appendChild($dom->createCDATASection($sous_chaine_restante_debut)); } $valeur->appendChild($dompar); // //On extrait à la sous chaine restante le paramètre variable trouvé $ch2 = substr($sous_chaine_restante, strlen($param)); } /* Si c'est le dernier paramètre à interpreter ou si on trouvé aucun paramètre à interpreter alors on ajoute le reste de texte */ $valeur->appendChild($dom->createCDATASection($ch2)); } else { $valeur->appendChild($dom->createCDATASection($ch2)); } $tpl->appendChild($o); } } return $dom->saveXML(); }
/** * Convert map $json to xml document. * * Use special keys "@attributes" = map, "@value|@cdata" = string * If root is default or empty and json is hash with single key and value is array use key as root. * * Example: * * XML::fromJSON(['A', 'B', 'C']) = <json2xml><vector>A</vector><vector>B</vector><vector>C</vector></json2xml> * XML::fromJSON(['names' => ['A', 'B', 'C']]) = <json2xml><names>A</names>...</json2xml> * * @throws rkphplib\Exception * @param map|string $json * @param map $root (default = 'json2xml') * @param map $xml (default = null = create DomDocument) * @return string|xmlElement */ public static function fromJSON($json, $root = 'json2xml', $xml = null) { $initial = false; if (is_null($xml)) { $xml = new \DomDocument('1.0', 'UTF-8'); $xml->preserveWhiteSpace = false; $xml->formatOutput = true; $initial = true; if ((empty($root) || $root == 'json2xml') && is_array($json)) { $jkeys = array_keys($json); if (count($jkeys) == 1 && count($json[$jkeys[0]]) > 1) { $json = $json[$jkeys[0]]; $root = $jkeys[0]; } } } if (!preg_match('/^[a-z_]+[a-z0-9\\:\\-\\.\\_]*[^:]*$/i', $root)) { throw new Exception('Invalid xml tag name ' . $root); } if (($node = $xml->createElement($root)) === false) { throw new Exception('Failed to create xml tag ' . $root); } if (!is_array($json)) { $json = (string) $json; if (substr($json, 0, 6) == '@file:') { $file = substr($json, 6); $node->setAttribute('file', $file); $node->setAttribute('encoding', 'base64'); $json = base64_encode(file_get_contents($file)); } if (mb_strlen($json) > 0) { $node->appendChild($xml->createTextNode($json)); } } else { if (isset($json['@attributes'])) { foreach ($json['@attributes'] as $key => $value) { if (!preg_match('/^[a-z_]+[a-z0-9\\:\\-\\.\\_]*[^:]*$/i', $key)) { throw new Exception("Invalid {$root} attribute name " . $key); } $node->setAttribute($key, (string) $value); } unset($json['@attributes']); } if (isset($json['@value'])) { $node->appendChild($xml->createTextNode((string) $json['@value'])); unset($json['@value']); } else { if (isset($json['@cdata'])) { $node->appendChild($xml->createCDATASection((string) $json['@cdata'])); unset($json['@cdata']); } } if ($initial && count(array_filter(array_keys($json), 'is_string')) == 0) { throw new Exception("Root level vector"); } foreach ($json as $key => $value) { if (is_array($value) && key($value) === 0) { // first key of $value is 0 ... assume value is vector use $key as tag foreach ($value as $k => $v) { $node->appendChild(self::fromJSON($v, $key, $xml)); } } else { $node->appendChild(self::fromJSON($value, $key, $xml)); } unset($json[$key]); } if (count($json) > 0) { print_r($json); } } if ($initial) { $xml->appendChild($node); return $xml->saveXML(); } return $node; }
function generateAjaxplorerActionsXML($application_nodes_) { $dom = new DomDocument('1.0', 'utf-8'); $driver_node = $dom->createElement('driver'); $driver_node->setAttribute('name', 'fs'); $driver_node->setAttribute('className', 'class.fsDriver.php'); $dom->appendChild($driver_node); $actions_node = $dom->createElement('actions'); $driver_node->appendChild($actions_node); $actions = array(); foreach ($application_nodes_ as $application_node) { $app_id = $application_node->getAttribute('id'); $app_name = $application_node->getAttribute('name'); $clientcallback_cdata = <<<EOF var repository; var path; if (window.actionArguments && window.actionArguments.length > 0) { \trepository = 0; \tpath = window.actionArguments[0]; } else { \tuserSelection = ajaxplorer.getFilesList().getUserSelection(); \tif (userSelection && userSelection.isUnique()) { \t\trepository = ajaxplorer.repositoryId; \t\tpath = userSelection.getUniqueFileName(); \t} } new Ajax.Request( \t'../start_app.php', \t{ \t\tmethod: 'post', \t\tparameters: { \t\t\tid: {$app_id}, \t\t\trepository: repository, \t\t\tpath: path \t\t} \t} ); EOF; $mimes = array(); foreach ($application_node->getElementsByTagName('mime') as $mime_node) { $mimes[] = $mime_node->getAttribute('type'); } $actions['ulteo' . $application_node->getAttribute('id')] = array('id' => $app_id, 'text' => $app_name, 'mimes' => $mimes, 'clientcallback' => $clientcallback_cdata); } foreach ($actions as $k => $v) { $action_node = $dom->createElement('action'); $action_node->setAttribute('name', $k); $action_node->setAttribute('fileDefault', 'false'); $actions_node->appendChild($action_node); $gui_node = $dom->createElement('gui'); $gui_node->setAttribute('text', $v['text']); $gui_node->setAttribute('title', $v['text']); $gui_node->setAttribute('src', '/ovd/icon.php?id=' . $v['id']); $gui_node->setAttribute('hasAccessKey', 'false'); $action_node->appendChild($gui_node); $context_node = $dom->createElement('context'); $context_node->setAttribute('selection', 'true'); $context_node->setAttribute('dir', 'false'); $context_node->setAttribute('recycle', 'false'); $context_node->setAttribute('actionBar', 'false'); $context_node->setAttribute('actionBarGroup', 'get'); $context_node->setAttribute('contextMenu', 'true'); $context_node->setAttribute('infoPanel', 'true'); $context_node->setAttribute('inZip', 'false'); $context_node->setAttribute('handleMimeTypes', 'true'); $gui_node->appendChild($context_node); foreach ($v['mimes'] as $mime) { $mime_node = $dom->createElement('mime'); $mime_node->setAttribute('type', $mime); $context_node->appendChild($mime_node); } $selectioncontext_node = $dom->createElement('selectionContext'); $selectioncontext_node->setAttribute('dir', 'false'); $selectioncontext_node->setAttribute('file', 'true'); $selectioncontext_node->setAttribute('recycle', 'false'); $selectioncontext_node->setAttribute('unique', 'true'); $gui_node->appendChild($selectioncontext_node); $rightscontext_node = $dom->createElement('rightsContext'); $rightscontext_node->setAttribute('noUser', 'true'); $rightscontext_node->setAttribute('userLogged', 'only'); $rightscontext_node->setAttribute('read', 'true'); $rightscontext_node->setAttribute('write', 'false'); $rightscontext_node->setAttribute('adminOnly', 'false'); $action_node->appendChild($rightscontext_node); $processing_node = $dom->createElement('processing'); $action_node->appendChild($processing_node); $clientcallback_node = $dom->createElement('clientCallback'); $clientcallback_node->setAttribute('prepareModal', 'true'); $clientcallback_cdata_node = $dom->createCDATASection($v['clientcallback']); $clientcallback_node->appendChild($clientcallback_cdata_node); $processing_node->appendChild($clientcallback_node); $servercallback_node = $dom->createElement('serverCallback'); $servercallback_node->setAttribute('methodName', 'switchAction'); $processing_node->appendChild($servercallback_node); } $xml = $dom->saveXML(); return $xml; }
/** * General manipulate wrapper method. * * @param string $input The XML fragment to be manipulated. We are only * interested in the <extension><CONTENTdmData> fragment added in the * MIK mappings file. * * @return string * One of the manipulated XML fragment, the original input XML if the * input is not the fragment we are interested in, or an empty string, * which as the effect of removing the empty <extension><CONTENTdmData> * fragement from our MODS (if there was an error, for example, we don't * want empty extension elements in our MODS documents). */ public function manipulate($input) { $dom = new \DomDocument(); $dom->loadxml($input, LIBXML_NSCLEAN); // Test to see if the current fragment is <extension><CONTENTdmData>. $xpath = new \DOMXPath($dom); $cdmdatas = $xpath->query("//extension/CONTENTdmData"); // There should only be one <CONTENTdmData> fragment in the incoming // XML. If there is 0 or more than 1, return the original. if ($cdmdatas->length === 1) { $contentdmdata = $cdmdatas->item(0); $alias = $dom->createElement('alias', $this->alias); $contentdmdata->appendChild($alias); $pointer = $dom->createElement('pointer', $this->record_key); $contentdmdata->appendChild($pointer); $timestamp = date("Y-m-d H:i:s"); // Add the <dmGetItemInfo> element. $dmGetItemInfo = $dom->createElement('dmGetItemInfo'); $now = $dom->createAttribute('timestamp'); $now->value = $timestamp; $dmGetItemInfo->appendChild($now); $mimetype = $dom->createAttribute('mimetype'); $mimetype->value = 'application/json'; $dmGetItemInfo->appendChild($mimetype); $source_url = $this->settings['METADATA_PARSER']['ws_url'] . 'dmGetItemInfo/' . $this->alias . '/' . $this->record_key . '/json'; $source = $dom->createAttribute('source'); $source->value = $source_url; $dmGetItemInfo->appendChild($source); $item_info = $this->getCdmData($this->alias, $this->record_key, 'dmGetItemInfo', 'json'); // CONTENTdm returns a 200 OK with its error messages, so we can't rely // on catching all 'errors' with the above try/catch block. Instead, we // check to see if the string 'dmcreated' (one of the metadata fields // returned for every object) is in the response body. If it's not, // assume CONTENTdm has returned an error of some sort, log it, and // return. if (!preg_match('/dmcreated/', $item_info)) { $this->log->addInfo("AddContentdmData", array('CONTENTdm internal error' => $item_info)); return ''; } // If the CONTENTdm metadata contains the CDATA end delimiter, log and return. if (preg_match('/\\]\\]>/', $item_info)) { $message = "CONTENTdm metadata for object " . $this->settings['METADATA_PARSER']['alias'] . '/' . $this->record_key . ' contains the CDATA end delimiter ]]>'; $this->log->addInfo("AddContentdmData", array('CONTENTdm metadata warning' => $message)); return ''; } // If we've made it this far, add the output of dmGetItemInfo to <CONTENTdmData> as // CDATA and return the modified XML fragment. if (strlen($item_info)) { $cdata = $dom->createCDATASection($item_info); $dmGetItemInfo->appendChild($cdata); $contentdmdata->appendChild($dmGetItemInfo); } // Add the <dmCompoundObjectInfo> element. $dmGetCompoundObjectInfo = $dom->createElement('dmGetCompoundObjectInfo'); $now = $dom->createAttribute('timestamp'); $now->value = $timestamp; $dmGetCompoundObjectInfo->appendChild($now); $mimetype = $dom->createAttribute('mimetype'); $mimetype->value = 'text/xml'; $dmGetCompoundObjectInfo->appendChild($mimetype); $source = $dom->createAttribute('source'); $source_url = $this->settings['METADATA_PARSER']['ws_url'] . 'dmGetCompoundObjectInfo/' . $this->alias . '/' . $this->record_key . '/xml'; $source->value = $source_url; $dmGetCompoundObjectInfo->appendChild($source); $compound_object_info = $this->getCdmData($this->alias, $this->record_key, 'dmGetCompoundObjectInfo', 'xml'); // Only add the <dmGetCompoundObjectInfo> element if the object is compound. if (strlen($compound_object_info) && preg_match('/<cpd>/', $compound_object_info)) { $cdata = $dom->createCDATASection($compound_object_info); $dmGetCompoundObjectInfo->appendChild($cdata); $contentdmdata->appendChild($dmGetCompoundObjectInfo); } // Add the <GetParent> element. $GetParent = $dom->createElement('GetParent'); $now = $dom->createAttribute('timestamp'); $now->value = $timestamp; $GetParent->appendChild($now); $mimetype = $dom->createAttribute('mimetype'); $mimetype->value = 'text/xml'; $GetParent->appendChild($mimetype); $source = $dom->createAttribute('source'); $source_url = $this->settings['METADATA_PARSER']['ws_url'] . 'GetParent/' . $this->alias . '/' . $this->record_key . '/xml'; $source->value = $source_url; $GetParent->appendChild($source); $parent_info = $this->getCdmData($this->alias, $this->record_key, 'GetParent', 'xml'); // Only add the <GetParent> element if the object has a parent // pointer of not -1. if (strlen($parent_info) && !preg_match('/\\-1/', $parent_info)) { $cdata = $dom->createCDATASection($parent_info); $GetParent->appendChild($cdata); $contentdmdata->appendChild($GetParent); } return $dom->saveXML($dom->documentElement); } else { // If current fragment is not <extension><CONTENTdmData>, return it // unmodified. return $input; } }
public function kml() { $app = JFactory::getApplication(); $Itemid = $app->input->getInt('Itemid', 0); $model = $this->getModel('Properties', 'JeaModel', array('ignore_request' => true)); $filters = $model->getFilters(); // Set the Model state foreach ($filters as $name => $value) { $model->setState('filter.' . $name, $app->input->get('filter_' . $name, null, 'default')); } // Deactivate pagination $model->setState('list.start', 0); $model->setState('list.limit', 0); // Set language state $model->setState('filter.language', $app->getLanguageFilter()); $items = $model->getItems(); $doc = new DomDocument(); $kmlNode = $doc->createElement('kml'); $kmlNode->setAttribute('xmlns', 'http://www.opengis.net/kml/2.2'); $documentNode = $doc->createElement('Document'); foreach ($items as $row) { if (abs($row->latitude) > 0 && abs($row->longitude) > 0) { $placemarkNode = $doc->createElement('Placemark'); $nameNode = $doc->createElement('name'); $descrNode = $doc->createElement('description'); $pointNode = $doc->createElement('Point'); // http://code.google.com/intl/fr/apis/kml/documentation/kml_tut.html#placemarks // (longitude, latitude, and optional altitude) $coordinates = $row->longitude . ',' . $row->latitude . ',0.000000'; $coordsNode = $doc->createElement('coordinates', $coordinates); $row->slug = $row->alias ? $row->id . ':' . $row->alias : $row->id; $url = JRoute::_('index.php?option=com_jea&view=property&id=' . $row->slug . '&Itemid=' . $Itemid); if (empty($row->title)) { $name = ucfirst(JText::sprintf('COM_JEA_PROPERTY_TYPE_IN_TOWN', $row->type, $row->town)); } else { $name = $row->title; } $description = '<div style="clear:both"></div>'; $images = json_decode($row->images); $image = null; if (!empty($images) && is_array($images)) { $image = array_shift($images); $imagePath = JPATH_ROOT . DS . 'images' . DS . 'com_jea'; $imageUrl = ''; if (file_exists($imagePath . DS . 'thumb-min' . DS . $row->id . '-' . $image->name)) { // If the thumbnail already exists, display it directly $baseURL = JURI::root(true); $imageUrl = $baseURL . '/images/com_jea/thumb-min/' . $row->id . '-' . $image->name; } elseif (file_exists($imagePath . DS . 'images' . DS . $row->id . DS . $image->name)) { // If the thumbnail doesn't exist, generate it and output it on the fly $url = 'index.php?option=com_jea&task=thumbnail.create&size=min&id=' . $row->id . '&image=' . $image->name; $imageUrl = JRoute::_($url); } $description .= '<img src="' . $imageUrl . '" alt="' . $image->name . '.jpg" style="float:left;margin-right:10px" />'; } $description .= substr(strip_tags($row->description), 0, 255) . ' ...' . '<p><a href="' . $url . '">' . JText::_('COM_JEA_DETAIL') . '</a></p>' . '<div style="clear:both"></div>'; $nameCDATA = $doc->createCDATASection($name); $descriptionCDATA = $doc->createCDATASection($description); $nameNode->appendChild($nameCDATA); $descrNode->appendChild($descriptionCDATA); $pointNode->appendChild($coordsNode); $placemarkNode->appendChild($nameNode); $placemarkNode->appendChild($descrNode); $placemarkNode->appendChild($pointNode); $documentNode->appendChild($placemarkNode); } } $kmlNode->appendChild($documentNode); $doc->appendChild($kmlNode); echo $doc->saveXML(); }
/** * create a new element in the channels dom * @param DomNode $target * @param string $tag * @param array $attributes * @param string $content * @param bool $cdata * @return DomNode */ protected function createElementOn(&$target, $tag, $attributes = false, $content = false, $cdata = false) { $_tag = $this->dom->createElement($tag); if (is_array($attributes)) { foreach ($attributes as $key => $value) { $attr = $this->dom->createAttribute($key); $attr_val = $this->dom->createTextNode($value); $attr->appendChild($attr_val); $_tag->appendChild($attr); } } if ($content) { if ($cdata) { $content = $this->dom->createCDATASection($content); } else { $content = $this->dom->createTextNode($content); } $_tag->appendChild($content); } $target->appendChild($_tag); return $_tag; }
/** * Get the answer value as an xml element * Add the PDF size as an attribute * @param \DomDocument $dom * @param \Jazzee\Entity\Answer $answer * @param integer $version * @return \DomElement */ public function getXmlAnswer(\DomDocument $dom, \Jazzee\Entity\Answer $answer, $version) { $eXml = $dom->createElement('element'); $eXml->setAttribute('elementId', $this->_element->getId()); $eXml->setAttribute('title', htmlentities($this->_element->getTitle(), ENT_COMPAT, 'utf-8')); $eXml->setAttribute('name', htmlentities($this->_element->getName(), ENT_COMPAT, 'utf-8')); $eXml->setAttribute('type', htmlentities($this->_element->getType()->getClass(), ENT_COMPAT, 'utf-8')); $eXml->setAttribute('weight', $this->_element->getWeight()); if ($value = $this->rawValue($answer)) { $eXml->setAttribute('size', strlen($value)); $eXml->appendChild($dom->createCDATASection(preg_replace('/[\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F]/', '', $value))); } return $eXml; }
function to_xml($include = array(), $usecdata = false, $obj = false, $skip_to_many = false) { if ($include == 'all') { $include = array_keys($this->to_one); $include = array_merge($include, array_keys($this->to_many)); } else { if ($include == 'to-one') { $include = array_keys($this->to_one); } else { if ($include == 'to-many') { $include = array_keys($this->to_many); } else { $include = is_array($include) ? $include : array($include); } } } # make doc and root $dom = new DomDocument(); $root = $dom->createElement($this->get_table()); $root = $dom->appendChild($root); # add id if ($this->get_id()) { $root->setAttribute('id', $this->get_id()); } # add node for each prop foreach ($this->data as $k => $v) { $node = $dom->createElement($k); if ($usecdata && (strpos($v, '<') !== false || strpos($v, '>') !== false || strpos($v, '&') !== false)) { $cdata = $dom->createCDATASection($v); } else { $cdata = $dom->createTextNode($v); } $node->appendChild($cdata); $node = $root->appendChild($node); } if (!empty($include)) { foreach ($include as $k => $v) { if ($rel = $this->has_relationship($v, 'all', true)) { if ($rel == 'to-many' && $skip_to_many) { continue; } $p = $this->{$v}; if (is_array($p)) { $list = $dom->createElement($v); $list = $root->appendChild($list); foreach ($p as $k2 => $v2) { $child = $dom->importNode($v2->to_xml($include, $usecdata, true, true)->documentElement, true); $child = $list->appendChild($child); } } else { $obj = $this->{$v}; $child = $dom->importNode($obj->to_xml($include, $usecdata, true, true)->documentElement, true); $child = $root->appendChild($child); } } } } return $obj ? $dom : $dom->saveXML(); }
/** * Set content as CDATA * * @param string $content * @return object $this */ public function cdata($content) { $this->current->appendChild($this->dom->createCDATASection($content)); return $this; }
/** * Print out the events in parameters into a formated events log file. * * @access public * @author Bertrand Chevrier, <*****@*****.**> * @param array events * @param string process_id * @param string folder * @param array eventFilter * @return boolean */ public function traceEvent($events, $process_id, $folder, $eventFilter = array()) { $returnValue = (bool) false; try { // $events_ = array( // array('name' => 'name1', 'type' => 'mousemove', 'time' => 'time1', 'key' => 'value'), // array('name' => 'name2', 'type' => 'click', 'time' => 'time2', 'key' => 'value'), // array('name' => 'name3', 'type' => 'type3', 'time' => 'time3', 'key' => 'value'), // array('name' => 'name4', 'type' => 'click', 'time' => 'time4', 'key' => 'value'), // array('name' => 'name5', 'type' => 'type5', 'time' => 'time5', 'key' => 'value') // ); // $events_ = json_encode($events_); if (is_dir($folder) && !empty($process_id)) { $file_pattern = $folder . '/' . $process_id; $i = 0; foreach (glob($file_pattern . '_*.xml') as $trace_file) { preg_match('/_([0-9]+).xml/', $trace_file, $matches); if ($matches[1] >= $i) { $i = $matches[1]; } } $trace_file = $file_pattern . '_' . $i . '.xml'; if (file_exists($trace_file) && filesize($trace_file) > 1024 * 8 * 10) { $trace_file = $file_pattern . '_' . ++$i . '.xml'; } $dom = new DomDocument(); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; // setting a lock for concurrency access $lock_pointer = fopen($file_pattern . '.lock', 'w'); flock($lock_pointer, LOCK_EX); if (file_exists($trace_file)) { $dom->load($trace_file); } else { $dom->loadXML('<events></events>'); } $event_type = array(); if (isset($eventFilter['list'])) { foreach ($eventFilter['list'] as $event_to_save_key => $event_to_save_value) { array_push($event_type, $event_to_save_key); } } $event_type_attributes = array(); if (isset($eventFilter['list'])) { foreach ($eventFilter['list'] as $event_to_save_key => $event_to_save_value) { $event_type_attributes[$event_to_save_key] = array(); foreach ($eventFilter['list'][$event_to_save_key] as $attribute_to_save_key => $attribute_to_save_value) { array_push($event_type_attributes[$event_to_save_key], $attribute_to_save_value); } //if no attribute is added in array, so we want to keep all attributes. if (count($event_type_attributes[$event_to_save_key]) == 0) { continue; } //adding business attribute to log every time. array_push($event_type_attributes[$event_to_save_key], 'id', 'name', 'type', 'time', 'ACTIVITYID', 'ITEMID', 'PROCESSURI', 'LAYOUT_DIRECTION', 'LANGID'); } } //adding business event to log every time. array_push($event_type, 'START_ITEM', 'END_ITEM', 'BUSINESS', 'ENDORSEMENT', 'RECOVERY'); if (is_array($events) && count($events) > 0) { foreach ($events as $event_index => $event_row) { // append the ($name_, $type_, $time_, ...) at eof as // <event> // <name><![CDATA[$name_]]></name> // <type><![CDATA[$type_]]></type> // <time><![CDATA[$time_]]></time> // ... // </event> $event_name = json_decode($event_row, true); if (isset($eventFilter['type'])) { if ($eventFilter['type'] == 'catch' && !in_array($event_name['type'], $event_type)) { continue; } if ($eventFilter['type'] == 'nocatch' && in_array($event_name['type'], $event_type)) { continue; } } $event_element = $dom->createElement('event'); foreach ($event_name as $key => $value) { //if equal to 0, we want to get all atributes if (isset($event_type_attributes[$event_name['type']]) && count($event_type_attributes[$event_name['type']]) != 0 && isset($eventFilter['type'])) { if ($eventFilter['type'] == 'catch' && !in_array($key, $event_type_attributes[$event_name['type']])) { continue; } if ($eventFilter['type'] == 'nocatch' && in_array($key, $event_type_attributes[$event_name['type']])) { continue; } } $key_element = $dom->createElement($key); $cdata_element = $dom->createCDATASection($value); $key_element->appendChild($cdata_element); $event_element->appendChild($key_element); } $dom->documentElement->appendChild($event_element); } if ($dom->save($trace_file) !== false) { $returnValue = true; } } // remove the lock of concurrency access flock($lock_pointer, LOCK_UN); fclose($lock_pointer); } } catch (Exception $e) { print $e; } return (bool) $returnValue; }
function getDocBody() { // Get currencies $currencies = Currency::getCurrencies(); // Get categories $categories = Category::getCategories($this->id_lang, true, false); // Generate XML here $xml = new DomDocument('1.0', 'UTF-8'); $catalog = $xml->createElement("yml_catalog"); $catalog->setAttribute("date", date('Y-m-d H:i')); $shop = $xml->createElement("shop"); $elem = $xml->createElement("name"); $elem->appendChild($xml->createCDATASection(html_entity_decode(Configuration::get('PS_SHOP_NAME')))); $shop->appendChild($elem); $elem = $xml->createElement("company"); $elem->appendChild($xml->createCDATASection(Configuration::get('YAMARKET_COMPANY_NAME'))); $shop->appendChild($elem); $shop->appendChild($xml->createElement("url", $this->proto_prefix . __PS_BASE_URI__)); $shop->appendChild($xml->createElement("platform", "PrestaShop")); $elem = $xml->createElement("currencies"); foreach ($currencies as $cur) { if ($cur['iso_code'] != 'GBP') { if ($cur['iso_code'] == 'RUB') { $cur['iso_code'] = 'RUR'; } $subelem = $xml->createElement("currency"); $subelem->setAttribute("id", $cur['iso_code']); $subelem->setAttribute("rate", 1 / $cur['conversion_rate']); $elem->appendChild($subelem); } } $shop->appendChild($elem); $elem = $xml->createElement("categories"); foreach ($categories as $category) { if ($category['id_category'] == 1) { continue; } $subelem = $xml->createElement("category", $category['name']); $subelem->setAttribute("id", $category['id_category']); if (array_key_exists('id_parent', $category) && $category['id_parent'] != 1) { $subelem->setAttribute("parentId", $category['id_parent']); } $elem->appendChild($subelem); } $shop->appendChild($elem); $local_delivery_price = Configuration::get('YAMARKET_DELIVERY_PRICE'); if ($local_delivery_price or $local_delivery_price === "0") { $shop->appendChild($xml->createElement("local_delivery_cost", $local_delivery_price)); } $catalog->appendChild($shop); $xml->appendChild($catalog); return $xml; }
$view_content = $obj->get_most_viewed_pages(); } catch (PAException $e) { $error = '<li>' . $e->message . '</li>'; } $html = '<ul>'; if (!empty($view_content)) { foreach ($view_content as $value) { if (!empty($value->title)) { $html .= '<li><a href= "' . $value->url . '">' . $value->title . '</a></li>'; } } } else { $html .= $error; } $html .= '</ul>'; //creating the rss $dom = new DomDocument(); $format = 'D, j M Y H:m:s O'; $rss = $dom->createElement('rss'); $attrib1 = $rss->setAttribute("xmlns:content", "http://purl.org/rss/1.0/modules/content/"); $attrib = $rss->setAttribute("version", "2.0"); $root = $dom->createElement("channel"); //this is the only item entry $node = $dom->createElement("item"); $description = $dom->createCDATASection($html); $node->appendChild($description); $root->appendChild($node); $rss->appendChild($root); $dom->appendChild($rss); header('Content-Type: text/xml'); print $dom->saveXml();