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; }
/** * Constructor * @return unknown_type */ public function __construct() { $this->_document = new DOMDocument(); //create structute /xml/content $this->_document->appendChild($this->_document->createElement('xml')); $this->_contentNode = $this->_document->createElement('content'); $this->_document->documentElement->appendChild($this->_contentNode); }
/** * @see Drest\Writer\Writer::write() */ public function write(ResultSet $data) { $this->xml = new \DomDocument('1.0', 'UTF-8'); $this->xml->formatOutput = true; $dataArray = $data->toArray(); if (key($dataArray) === 0) { // If there is no key, we need to use a default $this->xml->appendChild($this->convertArrayToXml('result', $dataArray)); } else { $this->xml->appendChild($this->convertArrayToXml(key($dataArray), $dataArray[key($dataArray)])); } $this->data = $this->xml->saveXML(); }
public function run() { $apiDocument = $this->document->createElement("api"); try { $apiDocument = $this->execute($apiDocument); } catch (ApiException $ex) { $exception = $this->document->createElement("error"); $exception->setAttribute("message", $ex->getMessage()); $apiDocument->appendChild($exception); } $this->document->appendChild($apiDocument); return $this->document->saveXml(); }
protected function setUp() { // Setup DOM $this->domDocument = new \DOMDocument('1', 'UTF-8'); $html = $this->domDocument->createElement('html'); $this->domAnchor = $this->domDocument->createElement('a', 'fake'); $this->domAnchor->setAttribute('href', 'http://php-spider.org/contact/'); $this->domDocument->appendChild($html); $html->appendChild($this->domAnchor); $this->uri = new DiscoveredUri(new Uri($this->domAnchor->getAttribute('href'))); // Setup Spider\Resource $content = $this->domDocument->saveHTML(); $this->spiderResource = new Resource($this->uri, new Response(200, [], $content)); }
function createCoursesDom($coursesArr) { global $langMyCoursesProf, $langMyCoursesUser; $dom = new DomDocument('1.0', 'utf-8'); if (defined('M_ROOT')) { $root0 = $dom->appendChild($dom->createElement(M_ROOT)); $root = $root0->appendChild($dom->createElement('courses')); $retroot = $root0; } else { $root = $dom->appendChild($dom->createElement('courses')); $retroot = $root; } if (isset($coursesArr) && count($coursesArr) > 0) { $k = 0; $this_status = 0; foreach ($coursesArr as $course) { $old_status = $this_status; $this_status = $course->status; if ($k == 0 || ($old_status != $this_status)) { $cg = $root->appendChild($dom->createElement('coursegroup')); $gname = ($this_status == 1) ? $langMyCoursesProf : $langMyCoursesUser; $cg->appendChild(new DOMAttr('name', $gname)); } $c = $cg->appendChild($dom->createElement('course')); $titleStr = ($course->code === $course->public_code) ? $course->title : $course->title . ' - ' . $course->public_code; $c->appendChild(new DOMAttr('code', $course->code)); $c->appendChild(new DOMAttr('title', $titleStr)); $c->appendChild(new DOMAttr('description', "")); //$c->appendChild(new DOMAttr('teacher', $course->titulaires)); //$c->appendChild(new DOMAttr('visible', $course->visible)); //$c->appendChild(new DOMAttr('visibleName', getVisibleName($course->visible))); $k++; } } $dom->formatOutput = true; return array($dom, $retroot); }
private function create_xml($respuesta, $rfc_emisor, $rfc_receptor, $total_factura, $uuid, $web_service, $hora_envio, $hora_recepcion, $md5) { $doc = new DomDocument('1.0', 'UTF-8'); $doc->formatOutput = true; $root = $doc->createElement('RespuestaSAT'); $doc->appendChild($root); $webService = $doc->createElement('WebService', "{$web_service}"); $root->appendChild($webService); $emisorRfc = $doc->createElement('EmisorRfc', "{$rfc_emisor}"); $root->appendChild($emisorRfc); $receptorRfc = $doc->createElement("ReceptorRFC", "{$rfc_receptor}"); $root->appendChild($receptorRfc); $FechaHoraEnvio = $doc->createElement("FechaHoraEnvio", "{$hora_envio}"); $root->appendChild($FechaHoraEnvio); $FechaHoraRespuesta = $doc->createElement("FechaHoraRespuesta", "{$hora_recepcion}"); $root->appendChild($FechaHoraRespuesta); $TotalFactura = $doc->createElement("TotalFactura", "{$total_factura}"); $root->appendChild($TotalFactura); $UUID = $doc->createElement("UUID", $uuid); $root->appendChild($UUID); $codigoEstatus = $doc->createElement('CodigoEstatus', $respuesta->ConsultaResult->CodigoEstatus); $root->appendChild($codigoEstatus); $estado = $doc->createElement('Estado', $respuesta->ConsultaResult->Estado); $root->appendChild($estado); $acuse = $doc->createElement("AcuseRecibo", "{$md5}"); $root->appendChild($acuse); // $doc->save('RespuestaSAT.xml'); // echo htmlentities($doc->saveXML()); return $doc; }
public function _toHtml() { $this->_checkRequired(); $info = $this->getInfo(); $certain = $info['certain']; $dom = new DomDocument(); $dom->preserveWhitespace = false; $block = $dom->createElement('block'); $attr = $dom->createAttribute('type'); $attr->value = $this->getAlias(); $block->appendChild($attr); $dom->appendChild($block); $output = simplexml_load_string('<block />'); foreach ($certain as $method) { $block->appendChild($dom->createComment("\n " . $this->_getDocumentation($method) . "\n ")); $dom_action = $dom->createElement('action'); $block->appendChild($dom_action); $dom_attr = $dom->createAttribute('method'); $dom_attr->value = $method->getName(); $dom_action->appendChild($dom_attr); $this->addParamsToDomActionNodeFromReflectionMethod($dom, $dom_action, $method); //$action = $this->addParamsToActionNodeFromReflectionMethod($action, $method); } $dom->formatOutput = true; return $this->_extraXmlFormatting($dom->saveXml()); }
protected function prepareData() { $v4b43b0aee35624cd95b910189b3dc231 = $this->reader; $v9a09b4dfda82e3e665e31092d1c3ec8d = new DomDocument(); $v5118e2d6cb8d101c16049b9cf18de377 = $v9a09b4dfda82e3e665e31092d1c3ec8d->createElement("yml_catalog"); $v9a09b4dfda82e3e665e31092d1c3ec8d->appendChild($v5118e2d6cb8d101c16049b9cf18de377); $v63a9f0ea7bb98050796b649e85481845 = $v9a09b4dfda82e3e665e31092d1c3ec8d->createElement("shop"); $v5118e2d6cb8d101c16049b9cf18de377->appendChild($v63a9f0ea7bb98050796b649e85481845); $v7a86c157ee9713c34fbd7a1ee40f0c5a = $this->offset; while ($v4b43b0aee35624cd95b910189b3dc231->read() && $v4b43b0aee35624cd95b910189b3dc231->name != 'categories') { if ($v4b43b0aee35624cd95b910189b3dc231->nodeType != XMLReader::ELEMENT) { continue; } if ($v4b43b0aee35624cd95b910189b3dc231->name == 'yml_catalog' || $v4b43b0aee35624cd95b910189b3dc231->name == 'shop') { continue; } $v8e2dcfd7e7e24b1ca76c1193f645902b = $v4b43b0aee35624cd95b910189b3dc231->expand(); $v63a9f0ea7bb98050796b649e85481845->appendChild($v8e2dcfd7e7e24b1ca76c1193f645902b); } $v4757fe07fd492a8be0ea6a760d683d6e = 0; while ($v4b43b0aee35624cd95b910189b3dc231->read() && $v4757fe07fd492a8be0ea6a760d683d6e < $v7a86c157ee9713c34fbd7a1ee40f0c5a) { if ($v4b43b0aee35624cd95b910189b3dc231->nodeType != XMLReader::ELEMENT) { continue; } if ($v4b43b0aee35624cd95b910189b3dc231->name == 'category' || $v4b43b0aee35624cd95b910189b3dc231->name == 'offer') { $v4757fe07fd492a8be0ea6a760d683d6e++; } } $this->offset += $v4757fe07fd492a8be0ea6a760d683d6e; $this->doc = $v9a09b4dfda82e3e665e31092d1c3ec8d; }
function file_write() { extract($GLOBALS); $dom = new DomDocument('1.0', 'UTF-8'); $prefs = $dom->appendChild($dom->createElement('prefs')); for ($i = 0; $i < 10; $i++) { $pref = $prefs->appendChild($dom->createElement('pref')); $pref->setAttribute('code', $power_company[$i] . '_Denryoku'); $pref->appendChild($dom->createElement('den_per', $Power[$power_company[$i]]["den_per"])); $pref->appendChild($dom->createElement('den_old', $Power[$power_company[$i]]["OLD_DATA"])); $pref->appendChild($dom->createElement('den_now', $Power[$power_company[$i]]["usage"])); $pref->appendChild($dom->createElement('den_updown', $Power[$power_company[$i]]["up_down"])); $pref->appendChild($dom->createElement('den_max', $Power[$power_company[$i]]["capacity"])); $pref->appendChild($dom->createElement('den_yosou', $Power[$power_company[$i]]["yosou"])); $pref->appendChild($dom->createElement('den_date', $Power[$power_company[$i]]["DATE"])); $pref->appendChild($dom->createElement('den_time', $Power[$power_company[$i]]["time"])); $pref->appendChild($dom->createElement('den_alive', $Power[$power_company[$i]]["alive"])); } $weekjp = array('日', '月', '火', '水', '木', '金', '土'); $weekno = date('w'); $week_X = "〔" . $weekjp[$weekno] . "〕"; $pref = $prefs->appendChild($dom->createElement('pref')); $pref->setAttribute('code', 'DATE'); $pref->appendChild($dom->createElement('time', date("Y年m月d日") . $week_X . date(" H時i分"))); $pref->appendChild($dom->createElement('time_ampm', date("Y年m月d日") . $week_X . date(" A h:i"))); $pref->appendChild($dom->createElement('time_x', date("Ymd"))); $dom->formatOutput = true; $save_file = "/etc/zabbix/externalscripts/" . $OUT_FILE; $dom->save($save_file); }
function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) { # capture some additional information $agent = $_SERVER['HTTP_USER_AGENT']; $ip = $_SERVER['REMOTE_ADDR']; $referrer = $_SERVER['HTTP_REFERER']; $dt = date("Y-m-d H:i:s (T)"); # grab email info if available global $err_email, $err_user_name; # use this to email problem to maintainer if maintainer info is set if (isset($err_user_name) && isset($err_email)) { } # Write error message to user with less details $xmldoc = new DomDocument('1.0'); $xmldoc->formatOutput = true; # Set root $root = $xmldoc->createElement("error_handler"); $root = $xmldoc->appendChild($root); # Set child $occ = $xmldoc->createElement("error"); $occ = $root->appendChild($occ); # Write error message $child = $xmldoc->createElement("error_message"); $child = $occ->appendChild($child); $fvalue = $xmldoc->createTextNode("Your request has returned an error: " . $errstr); $fvalue = $child->appendChild($fvalue); $xml_string = $xmldoc->saveXML(); echo $xml_string; # exit request exit; }
/** * @param $nameRoot - имя корня xml * @param $nameBigElement - имя узла в который записываются данные из массива $data * @param $data - массив с данными выгружеными из таблицы */ function createXml($nameRoot, $nameBigElement, $data) { // создает XML-строку и XML-документ при помощи DOM $dom = new DomDocument($this->version, $this->encode); // добавление корня $root = $dom->appendChild($dom->createElement($nameRoot)); // отбираем названия полей таблицы foreach (array_keys($data[0]) as $k) { if (is_string($k)) { $key[] = $k; } } // формируем элементы с данными foreach ($data as $d) { //добавление элемента $nameBigElement в корень $bigElement = $root->appendChild($dom->createElement($nameBigElement)); foreach ($key as $k) { $element = $bigElement->appendChild($dom->createElement($k)); $element->appendChild($dom->createTextNode($d[$k])); } } // сохраняем результат в файл $dom->save('format/' . $this->nameFile); unset($dom); }
/** * Convert a tree array (with depth) into a hierarchical XML string. * * @param $nodes|array Array with depth value. * * @return string */ public function toXml(array $nodes) { $xml = new DomDocument('1.0'); $xml->preserveWhiteSpace = false; $root = $xml->createElement('root'); $xml->appendChild($root); $depth = 0; $currentChildren = array(); foreach ($nodes as $node) { $element = $xml->createElement('element'); $element->setAttribute('id', $node['id']); $element->setAttribute('name', $node['name']); $element->setAttribute('lft', $node['lft']); $element->setAttribute('rgt', $node['rgt']); $children = $xml->createElement('children'); $element->appendChild($children); if ($node['depth'] == 0) { // Handle root $root->appendChild($element); $currentChildren[0] = $children; } elseif ($node['depth'] > $depth) { // is a new sub level $currentChildren[$depth]->appendChild($element); $currentChildren[$node['depth']] = $children; } elseif ($node['depth'] == $depth || $node['depth'] < $depth) { // is at the same level $currentChildren[$node['depth'] - 1]->appendChild($element); } $depth = $node['depth']; } return $xml->saveXML(); }
function makeXml($dbObject) { header("Content-Type: application/xml"); $doc = new DomDocument('1.0', 'UTF-8'); $uid = $doc->createElement('uid'); for ($i = 0; $i < $dbObject->rowCount(); $i++) { $result = $dbObject->fetch(); if ($i === 0) { $id = $doc->createAttribute('id'); $id->value = $result['usernum']; $uid->appendChild($id); $doc->appendChild($uid); } $prefix = array($result['num'], $result['in_out'], $result['type'], $result['amount'], $result['time'], $result['detail']); list($tnum, $inout, $type, $amount, $time, $detail) = $prefix; $trade_num = $doc->createElement('tnum'); $tr_att = $doc->createAttribute('nu'); $tr_att->value = $tnum; $trade_num->appendChild($tr_att); $trade_num->appendChild($doc->createElement('inout', $inout)); $trade_num->appendChild($doc->createElement('type', $type)); $trade_num->appendChild($doc->createElement('amount', $amount)); $trade_num->appendChild($doc->createElement('time', $time)); $trade_num->appendChild($doc->createElement('detail', $detail)); $uid->appendChild($trade_num); } $xml = $doc->saveXML(); print $xml; }
public function showAction() { set_time_limit(600); // 10 min // ini_set('output_buffering', '4096'); $nodeid = $this->getRequest()->getParam('id', -1); $this->_zip = new Uman_ZipStream("pack_{$nodeid}.pkg"); $xml = new DomDocument('1.0', 'utf-8'); $root = $xml->appendChild(new DOMElement('package')); $content = $xml->createElement('content'); $content = $root->appendChild($content); $this->addLevel($this->_db->fetchAll($this->_rootsql, $nodeid), $content, $this->getRequest()->getParam('contentinc', false)); $packid = $this->_db->nextSequenceId('GEN_UID'); $this->addInfo($nodeid, $root, $packid); $this->addTypes($root); $this->_zip->add_file('info.xml', $xml->saveXML()); $this->_zip->finish(); $AdminDbModel = new Admin_Model_Admin(); $AdminDbModel->exportPackage($nodeid, $packid); /* header("Content-type: application/x-zip"); header("Content-Disposition: attachment; filename=test.zip"); $zip = new ZipArchive(); if ($zip->open('php://output', ZIPARCHIVE::CREATE)!==TRUE) { // Пока не работает запись в поток echo "cannot open \n"; exit; } $zip->addFromString('test.txt', '11111111111'); $zip->close(); */ exit; }
private function createDatabaseConfigFile() { //Create database.xml file //$conf_file = fopen( "app/config/database.xml", "w" ); $dom_db = new DomDocument(); $database = $dom_db->createElement("database"); $dom_db->appendChild($database); if ($this->getApplication()->getRequest()->getPostData("dbms")) { $this->addNode($dom_db, $database, "dbms", $this->getApplication()->getRequest()->getPostData("dbms")); } if ($this->getApplication()->getRequest()->getPostData("host")) { $this->addNode($dom_db, $database, "host", $this->getApplication()->getRequest()->getPostData("host")); } if ($this->getApplication()->getRequest()->getPostData("db_name")) { $this->addNode($dom_db, $database, "dbname", $this->getApplication()->getRequest()->getPostData("db_name")); } if ($this->getApplication()->getRequest()->getPostData("user_name")) { $this->addNode($dom_db, $database, "user", $this->getApplication()->getRequest()->getPostData("user_name")); } if ($this->getApplication()->getRequest()->getPostData("password")) { $this->addNode($dom_db, $database, "password", $this->getApplication()->getRequest()->getPostData("password")); } if ($this->getApplication()->getRequest()->getPostData("flavor")) { $this->addNode($dom_db, $database, "flavor", $this->getApplication()->getRequest()->getPostData("flavor")); } $dom_db->formatOutput = TRUE; $dom_db->save('app/config/database.xml'); chmod('app/config/database.xml', 0640); }
function file_write() { extract($GLOBALS); $dom = new DomDocument('1.0', 'UTF-8'); $prefs = $dom->appendChild($dom->createElement('prefs')); $pref = $prefs->appendChild($dom->createElement('pref')); $pref->setAttribute('code', 'OpenWeatherMap'); $pref->appendChild($dom->createElement('place', $owm["place"])); $pref->appendChild($dom->createElement('description', $owm["description"])); $pref->appendChild($dom->createElement('clouds_value', $owm["clouds_value"])); $pref = $prefs->appendChild($dom->createElement('pref')); $pref->setAttribute('code', 'Wunderground'); $pref->appendChild($dom->createElement('city', $wg["city"])); $pref->appendChild($dom->createElement('weather', $wg["weather"])); $pref->appendChild($dom->createElement('kazamuki2', $wg["kazamuki2"])); $pref->appendChild($dom->createElement('kazamuki_degrees', $wg["kazamuki_degrees"])); $pref->appendChild($dom->createElement('temp_now2', $wg["temp_now2"])); $pref->appendChild($dom->createElement('temp_now_f', $wg["temp_now_f"])); $pref->appendChild($dom->createElement('feelslike', $wg["feelslike"])); $pref->appendChild($dom->createElement('humidity_now2', $wg["humidity_now2"])); $pref->appendChild($dom->createElement('windspeed_now2', $wg["windspeed_now2"])); $pref->appendChild($dom->createElement('pressure_now2', $wg["pressure_now2"])); $pref->appendChild($dom->createElement('discomfort', $wg["fukai"])); $weekjp = array('日', '月', '火', '水', '木', '金', '土'); $weekno = date('w'); $week_X = "〔" . $weekjp[$weekno] . "〕"; $pref = $prefs->appendChild($dom->createElement('pref')); $pref->setAttribute('code', 'DATE'); $pref->appendChild($dom->createElement('time', date("Y年m月j日") . $week_X . date(" H時i分"))); $pref->appendChild($dom->createElement('time_ampm', date("Y年m月j日") . $week_X . date(" A h:i"))); $dom->formatOutput = true; $save_file = "/etc/zabbix/externalscripts/" . $OUT_FILE; $dom->save($save_file); }
function do_refresh_task($task_id_) { $task = Abstract_Task::load($task_id_); if (!is_object($task)) { Logger::error('main', '(ajax/installable_applications) Task ' . $task_id_ . ' not found'); header('Content-Type: text/xml; charset=utf-8'); $dom = new DomDocument('1.0', 'utf-8'); $node = $dom->createElement('usage'); $node->setAttribute('status', 'task not found'); $dom->appendChild($node); die($dom->saveXML()); } $task->refresh(); if (!$task->succeed()) { header('Content-Type: text/xml; charset=utf-8'); $dom = new DomDocument('1.0', 'utf-8'); $node = $dom->createElement('task'); $node->setAttribute('status', $task->status); $dom->appendChild($node); die($dom->saveXML()); } $ret = $task->get_AllInfos(); header('Content-Type: text/xml; charset=utf-8'); die($ret['stdout']); }
function teste() { $xml = new DomDocument("1.0", "UTF-8"); /* $container = $xml->createElement('container', 'tkjasdkfjal'); $container = $xml->appendChild($container); $sale = $xml->createElement('sale'); $sale = $container->appendChild($sale); $item = $xml->createElement('item', 'Television'); $item = $sale->appendChild($item); $price = $xml->createElement('price', '$100'); $price = $sale->appendChild($price); */ $cadastro = $xml->createElement('Cadastro'); $cadastro = $xml->appendChild($cadastro); $pessoa = $xml->createElement('Pessoa'); $pessoa = $cadastro->appendChild($pessoa); $nome = $xml->createElement('nome', 'Rodrigo'); $pessoa->appendChild($nome); $situacao = $xml->createElement('situacao', 'fudido'); $pessoa->appendChild($situacao); $xml->FormatOutput = true; $string_value = $xml->saveXML(); $xml->save('xml/teste.xml'); echo 'xml criado, chupa mundo'; exit; //$xml = Xml::build('<example>text</example>', array('app/teste.xml')); //exit; }
/** flush printer buffer */ public function flush() { $document = new \DomDocument('1.0', 'ISO-8859-15'); $checkstyle = new \DOMElement('checkstyle'); $document->appendChild($checkstyle); $checkstyle->appendChild(new \DOMAttr('version', '6.5')); // Write each file to the DOM foreach ($this->files as $file_name => $error_list) { $file = new \DOMElement('file'); $checkstyle->appendChild($file); $file->appendChild(new \DOMAttr('name', $file_name)); // Write each error to the file foreach ($error_list as $error_map) { $error = new \DOMElement('error'); $file->appendChild($error); // Write each element of the error as an attribute // of the error foreach ($error_map as $key => $value) { $error->appendChild(new \DOMAttr($key, (string) $value)); } } } $this->output->write($document->saveXML()); $this->files = []; }
function createCollection($theUser, $pid, $soapClient) { $dom = new DomDocument("1.0", "UTF-8"); $dom->formatOutput = true; $rootElement = $dom->createElement("foxml:digitalObject"); $rootElement->setAttribute('PID', "{$pid}"); $rootElement->setAttribute('xmlns:foxml', "info:fedora/fedora-system:def/foxml#"); $rootElement->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance"); $rootElement->setAttribute('xsi:schemaLocation', "info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-0.xsd"); $dom->appendChild($rootElement); //create standard fedora stuff $this->createStandardFedoraStuff($theUser, $dom, $rootElement); //create dublin core $this->createDCStream($theUser, $dom, $rootElement); $value = $this->createPolicyStream($theUser, $dom, $rootElement); if (!$value) { return false; //error should already be logged. } $this->createCollectionPolicyStream($theUser, $dom, $rootElement); try { $params = array('objectXML' => $dom->saveXML(), 'format' => "foxml1.0", 'logMessage' => "Fedora Object Ingested"); $object = $soapClient->__soapCall('ingest', array($params)); } catch (exception $e) { drupal_set_message(t('Error Ingesting Personal Collection Object! ') . $e->getMessage(), 'error'); return false; } return true; }
/** * Build the validate address request * @return string * @throws \SimpleUPS\Api\MissingParameterException */ public function buildXml() { if (serialize($this->getAddress()) == serialize(new Address())) { throw new MissingParameterException('Address requires a Country code, Postal code, and either a City or State\\Province code'); } if ($this->getAddress()->getCountryCode() === null) { throw new MissingParameterException('Address requires a Country code'); } if ($this->getAddress()->getPostalCode() === null) { throw new MissingParameterException('Address requires a Postal code'); } $dom = new \DomDocument('1.0'); $dom->formatOutput = $this->getDebug(); $dom->appendChild($addressRequest = $dom->createElement('AddressValidationRequest')); $addressRequestLang = $dom->createAttribute('xml:lang'); $addressRequestLang->value = parent::getXmlLang(); $addressRequest->appendChild($request = $dom->createElement('Request')); $request->appendChild($transactionReference = $dom->createElement('TransactionReference')); $transactionReference->appendChild($dom->createElement('CustomerContext', $this->getCustomerContext())); $transactionReference->appendChild($dom->createElement('XpciVersion', $this->getXpciVersion())); $request->appendChild($dom->createElement('RequestAction', 'AV')); $addressRequest->appendChild($address = $dom->createElement('Address')); if ($this->getAddress()->getCity() != null) { $address->appendChild($dom->createElement('City', $this->getAddress()->getCity())); } if ($this->getAddress()->getStateProvinceCode() != null) { $address->appendChild($dom->createElement('StateProvinceCode', $this->getAddress()->getStateProvinceCode())); } if ($this->getAddress()->getPostalCode() != null) { $address->appendChild($dom->createElement('PostalCode', $this->getAddress()->getPostalCode())); } $address->appendChild($dom->createElement('CountryCode', $this->getAddress()->getCountryCode())); $xml = parent::buildAuthenticationXml() . $dom->saveXML(); return $xml; }
static function response($status, $status_message, $domdocument = null) { $dom = new DomDocument('1.0', 'UTF-8'); $results = $dom->appendChild($dom->createElement('response')); $results->appendChild($dom->createElement('status', $status)); $results->appendChild($dom->createElement('status_message', $status_message)); if (is_null($domdocument)) { $domdocument = new DomDocument('1.0', 'UTF-8'); $domdocument->appendChild($domdocument->createElement('data')); } if ($domdocument->documentElement->nodeName === 'data') { $newdom = $domdocument; } else { $newdom = new DOMDocument('1.0', 'UTF-8'); $data = $newdom->appendChild($newdom->createElement('data')); foreach ($domdocument->documentElement->childNodes as $domElement) { $domNode = $newdom->importNode($domElement, true); $data->appendChild($domNode); } } $import = $dom->importNode($newdom->documentElement, TRUE); $results->appendChild($import); $dom->formatOutput = true; echo $dom->saveXML(); }
public function Writer() { $this->writer = new DOMDocument("1.0", "utf-8"); $data = $this->writer->createElement("data"); $o = new DOMXPath($this->reader); $res = $o->query("//data/value/value[@key='info']/value[@key='caption']"); if ($res->length > 0) { $data->setAttribute("name", $res->item(0)->nodeValue); } $res = $o->query("//data/value/value[@key='info']/value[@key='project']"); if ($res->length > 0) { $data->setAttribute("project", $res->item(0)->nodeValue); } $res = $o->query("//data/value/value[@key='info']/value[@key='dateChanged']"); if ($res->length > 0) { $data->setAttribute("modifiedAt", $res->item(0)->nodeValue); } $res = $o->query("//data/value/value[@key='info']/value[@key='dateCreated']"); if ($res->length > 0) { $data->setAttribute("createdAt", $res->item(0)->nodeValue); } $res = $o->query("//value[@key='catalog']/value[@key='schemata']/value[@struct-name='db.mysql.Schema']/value[@key='name']"); if ($res->length > 0) { $data->setAttribute("schema", $res->item(0)->nodeValue); } $this->writer->appendChild($data); return $this; }
/** * Serialize an associative array of pci properties into a pci xml * * @param array $properties * @param string $ns * @return string */ private function serializePortableProperties($properties, $ns = '', $nsUri = '', $name = null, $element = null) { $document = null; $result = ''; if ($element === null) { $document = new \DomDocument(); $element = $ns ? $document->createElementNS($nsUri, $ns . ':properties') : $document->createElement('properties'); $document->appendChild($element); } else { $newElement = $ns ? $element->ownerDocument->createElementNS($nsUri, $ns . ':properties') : $element->ownerDocument->createElement('properties'); $element->appendChild($newElement); $element = $newElement; } if ($name !== null) { $element->setAttribute('key', $name); } foreach ($properties as $name => $value) { if (is_array($value)) { $this->serializePortableProperties($value, $ns, $nsUri, $name, $element); } else { $entryElement = $ns ? $element->ownerDocument->createElementNS($nsUri, $ns . ':entry') : $element->ownerDocument->createElementNS('entry'); $entryElement->setAttribute('key', $name); $entryElement->appendChild(new \DOMText($value)); $element->appendChild($entryElement); } } if ($document !== null) { foreach ($document->childNodes as $node) { $result .= $document->saveXML($node); } } return $result; }
/** * Build the validate address request * @internal * @return string * @throws \SimpleUPS\Api\MissingParameterException */ public function buildXml() { if ($this->getShipment()->getDestination() == null) { throw new MissingParameterException('Shipment destination is missing'); } $dom = new \DomDocument('1.0'); $dom->formatOutput = $this->getDebug(); $dom->appendChild($ratingRequest = $dom->createElement('RatingServiceSelectionRequest')); $addressRequestLang = $dom->createAttribute('xml:lang'); $addressRequestLang->value = parent::getXmlLang(); $ratingRequest->appendChild($request = $dom->createElement('Request')); $request->appendChild($transactionReference = $dom->createElement('TransactionReference')); $transactionReference->appendChild($dom->createElement('CustomerContext', $this->getCustomerContext())); $request->appendChild($dom->createElement('RequestAction', 'Rate')); $request->appendChild($dom->createElement('RequestOption', 'Shop')); //@todo test with "Rate" as setting to determine difference $ratingRequest->appendChild($pickupType = $dom->createElement('PickupType')); $pickupType->appendChild($shipmentType = $dom->createElement('Code', $this->getPickupType())); if ($this->getRateType() != null) { $ratingRequest->appendChild($customerClassification = $dom->createElement('CustomerClassification')); $customerClassification->appendChild($dom->createElement('Code', $this->getRateType())); } // Shipment $shipment = $this->getShipment(); $shipment->setShipper(UPS::getShipper()); $ratingRequest->appendChild($shipment->toXml($dom)); $xml = parent::buildAuthenticationXml() . $dom->saveXML(); return $xml; }
/** * Renders an rss feed containing the newest plugins. * * @param int $limit How many plugins to display (optional, default 20) */ public function newest_action($limit = 20) { $doc = new DomDocument('1.0', 'utf-8'); $doc->formatOutput = true; $doc->encoding = 'utf-8'; $rss = $doc->appendChild($this->create_xml_element($doc, 'rss', null, array('version' => '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom'))); $channel = $rss->appendChild($doc->createElement('channel')); $channel->appendChild($this->create_xml_element($doc, 'title', 'Stud.IP Plugin Marktplatz - Neueste Plugins')); $channel->appendChild($this->create_xml_element($doc, 'description', 'Liste der neuesten Plugins auf dem Stud.IP Plugin Marktplatz')); $channel->appendChild($this->create_xml_element($doc, 'link', 'http://plugins.studip.de')); $channel->appendChild($this->create_xml_element($doc, 'lastBuildDate', gmdate('D, d M Y H:i:s T'))); $channel->appendChild($this->create_xml_element($doc, 'generator', _('Stud.IP Plugin Marktplatz'))); $channel->appendChild($this->create_xml_element($doc, 'atom:link', null, array('rel' => 'self', 'type' => 'application/rss+xml', 'href' => $this->absolute_url_for('rss/newest')))); $plugins = MarketPlugin::findBySQL("publiclyvisible = 1 AND approved = 1 ORDER BY mkdate DESC"); foreach ($plugins as $plugin) { if (count($plugin->releases) === 0) { continue; } $rss_plugin = $channel->appendChild($doc->createElement('item')); $rss_plugin->appendChild($this->create_xml_element($doc, 'title', $plugin->name)); $rss_plugin->appendChild($this->create_xml_element($doc, 'link', $this->absolute_url_for('presenting/details/' . $plugin->id))); $rss_plugin->appendChild($this->create_xml_element($doc, 'guid', $this->absolute_url_for('presenting/details/' . $plugin->id), array('isPermaLink' => 'true'))); $rss_plugin->appendChild($this->create_xml_element($doc, 'description', $plugin->description, array(), false)); if ($plugin->user) { $rss_plugin->appendChild($this->create_xml_element($doc, 'author', $plugin->user->email . ' (' . $plugin->user->getFullname() . ')')); } } $this->render_text($doc->saveXML()); }
/** * @return string */ public function getString() { // ensure the xml has the required xpacket processing instructions $result = $this->xpath->query('/processing-instruction(\'xpacket\')'); $hasBegin = $hasEnd = false; /** @var $item \DOMProcessingInstruction */ foreach ($result as $item) { // do a quick check if the processing instruction contains 'begin' or 'end' if (false !== stripos($item->nodeValue, 'begin')) { $hasBegin = true; } elseif (false !== stripos($item->nodeValue, 'end')) { $hasEnd = true; } } if (!$hasBegin) { $this->dom->insertBefore($this->dom->createProcessingInstruction('xpacket', "begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\""), $this->dom->documentElement); } if (!$hasEnd) { $this->dom->appendChild($this->dom->createProcessingInstruction('xpacket', 'end="w"')); // append to end } // ensure all rdf:Description elements have an rdf:about attribute $descriptions = $this->xpath->query('//rdf:Description'); for ($i = 0; $i < $descriptions->length; $i++) { /** @var \DOMElement $desc */ $desc = $descriptions->item($i); $desc->setAttributeNS(self::RDF_NS, 'rdf:about', $this->about); } return $this->dom->saveXML(); }
/** * @param string $rootNode * @param array $inputArray * @param string $version * @param string $encoding * @return DOMDocument */ public function buildXml($rootNode, array $inputArray, $version = '1.0', $encoding = 'utf-8') { $xml = new DomDocument($version, $encoding); $xml->formatOutput = true; $xml->appendChild($this->convert($rootNode, $inputArray, $xml)); return $xml; }
function file_write() { extract($GLOBALS); $dom = new DomDocument('1.0', 'UTF-8'); $prefs = $dom->appendChild($dom->createElement('prefs')); $pref = $prefs->appendChild($dom->createElement('pref')); $pref->setAttribute('code', 'FullMoon'); $pref->appendChild($dom->createElement('Date', $FM[0] . "-" . $FM[1] . "-" . $FM[2])); $pref->appendChild($dom->createElement('Time', $FM[3] . ":" . $FM[4] . ":" . $FM[5])); $day = day_diff(date('Y-m-d'), $FM[0] . "-" . $FM[1] . "-" . $FM[2]); if ($day < 0) { $day = "--"; } $pref->appendChild($dom->createElement('Wait', $day)); $pref = $prefs->appendChild($dom->createElement('pref')); $pref->setAttribute('code', 'NewMoon'); $pref->appendChild($dom->createElement('Date', $NM[0] . "-" . $NM[1] . "-" . $NM[2])); $pref->appendChild($dom->createElement('Time', $NM[3] . ":" . $NM[4] . ":" . $NM[5])); $day = day_diff(date('Y-m-d'), $NM[0] . "-" . $NM[1] . "-" . $NM[2]); if ($day < 0) { $day = "--"; } $pref->appendChild($dom->createElement('Wait', $day)); $weekjp = array('日', '月', '火', '水', '木', '金', '土'); $weekno = date('w'); $week_X = "〔" . $weekjp[$weekno] . "〕"; $pref = $prefs->appendChild($dom->createElement('pref')); $pref->setAttribute('code', 'DATE'); $pref->appendChild($dom->createElement('time', date("Y年m月j日") . $week_X . date(" H時i分"))); $pref->appendChild($dom->createElement('time_ampm', date("Y年m月j日") . $week_X . date(" A h:i"))); $dom->formatOutput = true; $save_file = "/etc/zabbix/externalscripts/F_N_Moon.xml"; $dom->save($save_file); }