public function execute(InputInterface $input, OutputInterface $output) { $file = $input->getArgument('file'); if (!preg_match("'^/|(?:[^:\\\\/]+://)|(?:[a-z]:[\\\\/])'i", $file)) { $file = $this->directory . '/resource/' . $file . '.html.xml'; } $file = Filesystem::normalizePath($file); $questionHelper = $this->getHelper('question'); $question = new ConfirmationQuestion(sprintf('Create view <info>%s</info>? [n] ', $file), false); if (!$questionHelper->ask($input, $output, $question)) { return; } $xml = new \DOMDocument('1.0', 'UTF-8'); $xml->formatOutput = true; $root = $xml->appendChild($xml->createElementNS(ExpressViewParser::NS_EXPRESS, 'k:composition')); $root->appendChild($xml->createAttribute('extends')); $root->appendChild($xml->createAttribute('xmlns'))->appendChild($xml->createTextNode(ExpressViewParser::NS_XHTML)); $root->appendChild($xml->createTextNode("\n\n ")); $block = $root->appendChild($xml->createElementNS(ExpressViewParser::NS_EXPRESS, 'k:block')); $block->appendChild($xml->createAttribute('name'))->appendChild($xml->createTextNode('main')); $block->appendChild($xml->createTextNode("\n TODO: Create composition contents...\n ")); $root->appendChild($xml->createTextNode("\n\n")); Filesystem::writeFile($file, $xml->saveXML()); $output->writeln(''); $output->writeln(sprintf('CREATED: <info>%s</info>', $file)); }
function addCustomerToIndex($customerId) { $indexDoc = simplexml_load_file('customer-index.xml'); $lastValue = $indexDoc->lastIndex; $lastValue = $lastValue + 1; $dom = new DOMDocument(); $dom->load("customer-index.xml"); $value = '2290000000' . $lastValue; $dom->getElementsByTagName('lastIndex')->item(0)->nodeValue = $lastValue; //update the last value //$doc->getElementsByTagName("title")->item(0)->nodeValue = $titleText; $customerElement = $dom->createElement('customer'); //createNode($dom, $dom->customers,'customer'); $custIdAttr = $dom->createAttribute('customer_id'); $custIdVal = $dom->createTextNode($customerId); $custIdAttr->appendChild($custIdVal); $customerElement->appendChild($custIdAttr); $suIdAttr = $dom->createAttribute('cust_sid'); $suIdVal = $dom->createTextNode($value); $suIdAttr->appendChild($suIdVal); $customerElement->appendChild($suIdAttr); $dom->getElementsByTagName('customers')->item(0)->appendChild($customerElement); $dom->save('customer-index.xml'); return $value; }
function geraXML() { $this->Id = 'ID' . $this->cUF . $this->CNPJ . $this->mod . $this->serie . $this->nNFIni . $this->nNFFin; $dom = new DOMDocument('1.0', 'utf-8'); $dom->formatOutput = false; $DP01 = $dom->appendChild($dom->createElement('inutNFe')); $DP01_att1 = $DP01->appendChild($dom->createAttribute('versao')); $DP01_att1->appendChild($dom->createTextNode($this->versao)); $DP01_att2 = $DP01->appendChild($dom->createAttribute('xmlns')); $DP01_att2->appendChild($dom->createTextNode('http://www.portalfiscal.inf.br/nfe')); $DP03 = $DP01->appendChild($dom->createElement('infInut')); $DP04 = $DP03->setAttribute('Id', $this->Id); $DP05 = $DP03->appendChild($dom->createElement('tpAmb', $this->tpAmb)); $DP06 = $DP03->appendChild($dom->createElement('xServ', $this->xServ)); $DP07 = $DP03->appendChild($dom->createElement('cUF', $this->cUF)); $DP08 = $DP03->appendChild($dom->createElement('ano', $this->ano)); $DP09 = $DP03->appendChild($dom->createElement('CNPJ', $this->CNPJ)); $DP10 = $DP03->appendChild($dom->createElement('mod', $this->mod)); $DP11 = $DP03->appendChild($dom->createElement('serie', $this->serie)); $DP12 = $DP03->appendChild($dom->createElement('nNFIni', $this->nNFIni)); $DP13 = $DP03->appendChild($dom->createElement('nNFFin', $this->nNFFin)); $DP14 = $DP03->appendChild($dom->createElement('xJust', $this->xJust)); $xml = $dom->saveXML(); $assinatura = new assinatura(); $this->XML = $assinatura->assinaXML($xml, 'infInut'); return $this->XML; }
public function render($caption_set, $file = false) { $dom = new \DOMDocument("1.0"); $dom->formatOutput = true; $root = $dom->createElement('tt'); $dom->appendChild($root); $body = $dom->createElement('body'); $root->appendChild($body); $xmlns = $dom->createAttribute('xmlns'); $xmlns->appendChild($dom->createTextNode('http://www.w3.org/ns/ttml')); $root->appendChild($xmlns); $div = $dom->createElement('div'); $body->appendChild($div); foreach ($caption_set->captions() as $index => $caption) { $entry = $dom->createElement('p'); $from = $dom->createAttribute('begin'); $from->appendChild($dom->createTextNode(DfxpHelper::time_to_string($caption->start()))); $entry->appendChild($from); $to = $dom->createAttribute('end'); $to->appendChild($dom->createTextNode(DfxpHelper::time_to_string($caption->end()))); $entry->appendChild($to); $entry->appendChild($dom->createCDATASection($caption->text())); $div->appendChild($entry); } if ($file) { return file_put_contents($file, $dom->saveXML()); } else { return $dom->saveHTML(); } }
public static function busdetail($data) { //print_r($data); exit; $date = date('Y-m-d', strtotime($data['formdate'])); //header("Content-Type: text/xml"); $xmlDoc = new DOMDocument(); $root = $xmlDoc->appendChild($xmlDoc->createElement("soapenv:Envelope")); $root->appendChild($xmlDoc->createAttribute("xmlns:soapenv"))->appendChild($xmlDoc->createTextNode("http://www.w3.org/2003/05/soap-envelope")); $root->appendChild($xmlDoc->createAttribute("xmlns:bus"))->appendChild($xmlDoc->createTextNode("http://192.168.0.131/TT/BusBookingAPI")); $header = $root->appendChild($xmlDoc->createElement("soapenv:Header")); $authenticationdata = $header->appendChild($xmlDoc->createElement("bus:AuthenticationData")); //$authenticationdata->appendChild( //$xmlDoc->createElement("bus:SiteName","")); //$authenticationdata->appendChild( //$xmlDoc->createElement("bus:AccountCode","")); $authenticationdata->appendChild($xmlDoc->createElement("bus:UserName", "appan")); $authenticationdata->appendChild($xmlDoc->createElement("bus:Password", "appan@1234")); $body = $root->appendChild($xmlDoc->createElement("soapenv:Body")); $searchrequest = $body->appendChild($xmlDoc->createElement("bus:Search")); $search = $searchrequest->appendChild($xmlDoc->createElement("bus:wsBusSearchRequest")); $search->appendChild($xmlDoc->createElement("bus:SourceId", $data['formplace'])); $search->appendChild($xmlDoc->createElement("bus:DestinationId", $data['toplace'])); $search->appendChild($xmlDoc->createElement("bus:DateOfJourney", $date)); $search->appendChild($xmlDoc->createElement("bus:SourceName", $data['sourcename'])); $search->appendChild($xmlDoc->createElement("bus:DestinationName", $data['destinationname'])); $search->appendChild($xmlDoc->createElement("bus:IsDomestic", '1')); $xmlDoc->formatOutput = true; //print_r($xmlDoc); return $xmlDoc->saveXML(); }
/** * generating DOMDocument object for sitemap.xml based on the links array based * @param OutputInterface $output * @param array $links array holds links information derived from Arachnide * @param string $frequency * @return \DOMDocument */ protected function getSitemapDocument(OutputInterface $output, array $links, $frequency) { $xmlDoc = new \DOMDocument("1.0", "UTF-8"); $urlset = $xmlDoc->createElement('urlset'); $xmlns = $xmlDoc->createAttribute('xmlns'); $xmlns->value = "http://www.sitemaps.org/schemas/sitemap/0.9"; $xmlns_xsi = $xmlDoc->createAttribute('xmlns:xsi'); $xmlns_xsi->value = "http://www.w3.org/2001/XMLSchema-instance"; $xsi_schemaLocation = $xmlDoc->createAttribute('xsi:schemaLocation'); $xsi_schemaLocation->value = "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"; $urlset->appendChild($xmlns); $urlset->appendChild($xmlns_xsi); $urlset->appendChild($xsi_schemaLocation); $output->writeln('<info>Adding links to sitemap:</info>'); foreach ($links as $uri => $link) { if (isset($link['absolute_url']) === false) { continue; } if ($link['external_link'] === true) { //never add link pointing to other site to sitemap.xml continue; } $url = $xmlDoc->createElement('url'); $loc = $xmlDoc->createElement('loc', $link['absolute_url']); $changefreq = $xmlDoc->createElement('changefreq', $frequency); $priority = $xmlDoc->createElement('priority', '1.00'); $url->appendChild($loc); $url->appendChild($changefreq); $url->appendChild($priority); $urlset->appendChild($url); $output->writeln('<comment>' . $link['absolute_url'] . '</comment>'); } $xmlDoc->appendChild($urlset); return $xmlDoc; }
function render() { $dom = new DOMDocument("1.0"); $root = $dom->createElement("gpx"); $dom->appendChild($root); $creator = $dom->createAttribute("createor"); $version = $dom->createAttribute("version"); $version_value = $dom->createTextNode("1.0"); $version->appendChild($version_value); $root->appendChild($creator); $root->appendChild($version); $trk = $dom->createElement("trk"); $root->appendChild($trk); $trkseg = $dom->createElement("trkseg"); $trk->appendChild($trkseg); /* Create the items */ foreach ($this->data as $point) { $trkpt = $dom->createElement("trkpt"); foreach ($point as $key => $value) { $attribute = $dom->createAttribute($key); $text = $dom->createTextNode($value); $attribute->appendChild($text); $trkpt->appendChild($attribute); } $trkseg->appendChild($trkpt); } header("Content-type: text/xml"); return $dom->saveXML(); }
/** * Get configs xml object. * * @return \DOMDocument */ public function getXml() { $dom = new DOMDocument('1.0', 'UTF-8'); $dom->xmlStandalone = false; $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $configs = $dom->createElement('configs'); $attr_delete = $dom->createAttribute('delete'); $attr_delete->value = $this->delete === true ? 'true' : 'false'; $configs->appendChild($attr_delete); if (!empty($this->valid_to)) { $attr_valid_to = $dom->createAttribute('valid_to'); $attr_valid_to->value = date('c', $this->valid_to); $configs->appendChild($attr_valid_to); } foreach ($this->configs as $config) { /* @var $config Guacamole_Config_Protocol_Abstract */ foreach ($config->getXml()->getElementsByTagName('config') as $dom_element) { $local_dom_element = $dom->importNode($dom_element, true); $configs->appendChild($local_dom_element); } } $dom->appendChild($configs); return $dom; }
/** * Map a set of node attributes to a node. * * @param DOMNode $node * @param array $attributes */ public function nodeAttributes(&$node, $attributes) { foreach ($attributes as $key => $value) { $attribute = $this->dom->createAttribute($key); $attribute->value = $value; $node->appendChild($attribute); } }
public function create() { // No user menu in client mode. if (Filter_Client::enabled()) { return ""; } // Modify the menu based on user access level. $mainmenu = $this->accesscontrol($this->mainmenu()); // To create CSS menu the HTML structure needs to be like this: // <ul id="menu" class="menu"> // <li> // Menu entry // <li>Subitem</li> // </ul> // </li> // <li>Another entry</li> // </ul> $document = new DOMDocument("1.0", "UTF-8"); $document->encoding = "UTF-8"; $document->preserveWhiteSpace = false; $document->loadXML('<ul id="usermenu" class="menu"></ul>'); $xpath = new DOMXpath($document); $nodes = $xpath->query("//ul"); $mainul = $nodes->item(0); // Go through the main menu. foreach ($mainmenu as $mainitem) { // Build the main menu. $mainhref = $mainitem[0]; $maintext = $mainitem[1]; $mainli = $document->createElement("li"); $attribute = $document->createAttribute("class"); $mainli->appendChild($attribute); $attribute->value = "toggle"; $mainul->appendChild($mainli); if ($mainhref == "") { $mainaspan = $document->createElement("span"); } else { $mainaspan = $document->createElement("a"); $attribute = $document->createAttribute("href"); $mainaspan->appendChild($attribute); $attribute->value = $mainhref; } $mainli->appendChild($mainaspan); $mainaspan->nodeValue = $maintext; // Build the submenu. $submenu = $mainitem[2]; if (!$submenu) { continue; } $this->submenu($document, $mainli, $submenu); } // Get the result. $document->formatOutput = true; $menu = $document->saveXML($mainul); return $menu; }
/** * Ajoute un paquet a la liste des paquets installes. * @param Package $package Le paquet a ajouter. */ public function addPackage(Package $package) { //Si le paquet est deja installe, on enleve l'ancien if ($this->isPackage($package->getName())) { $oldPackage = $this->getPackage($package->getName()); $oldPackage->remove(); } $xml = new \DOMDocument('1.0'); if ($this->webos->managers()->get('File')->exists($this->source . '/packages.xml')) { $xml->loadXML($this->webos->managers()->get('File')->get($this->source . '/packages.xml')->contents()); $root = $xml->getElementsByTagName('packages')->item(0); } else { $root = $xml->createElement('packages'); $xml->appendChild($root); } $element = $xml->createElement('package'); $root->appendChild($element); $name = $xml->createAttribute('name'); $name->appendChild($xml->createTextNode($package->getName())); $element->appendChild($name); $version = $xml->createAttribute('version'); $version->appendChild($xml->createTextNode($package->getVersion()->getVersion())); $element->appendChild($version); $this->webos->managers()->get('File')->get($this->source . '/packages.xml')->setContents($xml->saveXML()); $xml = new \DOMDocument('1.0'); $root = $xml->createElement('package'); $xml->appendChild($root); $xml_attributes = $xml->createElement('attributes'); $root->appendChild($xml_attributes); $attributes = $package->getAttributes(); $attributes['installed_time'] = time(); $attributes['source'] = $package->getRepositorySource(); foreach ($attributes as $attribute => $value) { $node = $xml->createElement('attribute'); $xml_attributes->appendChild($node); $name = $xml->createAttribute('name'); $name->appendChild($xml->createTextNode($attribute)); $node->appendChild($name); $val = $xml->createAttribute('value'); $val->appendChild($xml->createTextNode($value)); $node->appendChild($val); } $files = $package->getFiles(); $xml_files = $xml->createElement('files'); $root->appendChild($xml_files); foreach ($files as $file) { $node = $xml->createElement('file'); $xml_files->appendChild($node); $path = $xml->createAttribute('path'); $path->appendChild($xml->createTextNode($file)); $node->appendChild($path); } $this->webos->managers()->get('File')->createFile($this->source . '/packages/' . $package->getName() . '.xml')->setContents($xml->saveXML()); $newPackage = new InstalledPackage($this->webos, $this, $package->getName()); $this->packages[$package->getName()] = $newPackage; }
/** * SitemapGen constructor. */ public function __construct() { $this->dom = new DOMDocument(); $this->dom->formatOutput = true; $this->root = $this->dom->createElement("urlset"); $this->dom->appendChild($this->root); $rootAttr = $this->dom->createAttribute('xmlns'); $this->root->appendChild($rootAttr); $rootAttrText = $this->dom->createTextNode('http://www.sitemaps.org/schemas/sitemap/0.9'); $rootAttr->appendChild($rootAttrText); }
function getCabec($versao) { $dom = new DOMDocument('1.0', 'utf-8'); $dom->formatOutput = false; $raiz = $dom->appendChild($dom->createElement('cabecMsg')); $raiz_att1 = $raiz->appendChild($dom->createAttribute('versao')); $raiz_att1->appendChild($dom->createTextNode('1.02')); $raiz_att2 = $raiz->appendChild($dom->createAttribute('xmlns')); $raiz_att2->appendChild($dom->createTextNode('http://www.portalfiscal.inf.br/nfe')); $raiz->appendChild($dom->createElement('versaoDados', $versao)); return $this->XML = $dom->saveXML(); }
public function createxml($array, $url) { $citysall = explode(";", $array['citys']); if (is_array($citysall)) { $dom2 = new DOMDocument('1.0', 'utf-8'); $path2 = $url . '/limitarea.xml'; @$dom2->load($path2); //清空 $ads = $dom2->getElementsByTagName('address'); for ($a = 0; $a < $ads->length; $a++) { $ad = $ads->item($a); $ad->parentNode->removeChild($ad); } //清空 $address = $dom2->createElement('address'); $dom2->appendChild($address); $path = IA_ROOT . '/addons/feng_fightgroups/template/amyarea.xml'; $xml = simplexml_load_file($path); $provinces = $xml->province; for ($i = 0; $i < count($provinces); $i++) { $province = $provinces[$i]; foreach ($citysall as $key => $value) { if ($province['name'] == $value) { $shen = $dom2->createElement('province'); $name1 = $dom2->createAttribute('name'); $name1->nodeValue = $province['name']; $shen->setAttributeNode($name1); $address->appendChild($shen); $citys = $province->city; for ($j = 0; $j < count($citys); $j++) { $city = $citys[$j]; $chen = $dom2->createElement('city'); $name2 = $dom2->createAttribute('name'); $name2->nodeValue = $city['name']; $chen->setAttributeNode($name2); $shen->appendChild($chen); $countys = $city->county; for ($k = 0; $k < count($countys); $k++) { $county = $countys[$k]; $qu = $dom2->createElement('county'); $name3 = $dom2->createAttribute('name'); $name3->nodeValue = $county['name']; $qu->setAttributeNode($name3); $chen->appendChild($qu); } } } } } $dom2->save($path2); } }
function geraXML() { $dom = new DOMDocument('1.0', 'utf-8'); $dom->formatOutput = false; $EP01 = $dom->appendChild($dom->createElement('consSitNFe')); $EP01_att1 = $EP01->appendChild($dom->createAttribute('versao')); $EP01_att1->appendChild($dom->createTextNode($this->versao)); $EP01_att2 = $EP01->appendChild($dom->createAttribute('xmlns')); $EP01_att2->appendChild($dom->createTextNode('http://www.portalfiscal.inf.br/nfe')); $EP03 = $EP01->appendChild($dom->createElement('tpAmb', $this->tpAmb)); $EP04 = $EP01->appendChild($dom->createElement('xServ', $this->xServ)); $EP05 = $EP01->appendChild($dom->createElement('chNFe', $this->chNFe)); return $this->XML = $dom->saveXML(); }
/** * {@inheritdoc} */ public function toXml() { $gnre = new \DOMDocument('1.0', 'UTF-8'); $gnre->formatOutput = false; $gnre->preserveWhiteSpace = false; $loteGnre = $gnre->createElement('TLote_GNRE'); $loteXmlns = $gnre->createAttribute('xmlns'); $loteXmlns->value = 'http://www.gnre.pe.gov.br'; $loteGnre->appendChild($loteXmlns); $guia = $gnre->createElement('guias'); foreach ($this->getGuias() as $gnreGuia) { $guia->appendChild($gnreGuia->toXml($gnre)); } $loteGnre->appendChild($guia); $gnre->appendChild($loteGnre); $soapEnv = $gnre->createElement('soap12:Envelope'); $soapEnv->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $soapEnv->setAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema'); $soapEnv->setAttribute('xmlns:soap12', 'http://www.w3.org/2003/05/soap-envelope'); $gnreCabecalhoSoap = $gnre->createElement('gnreCabecMsg'); $gnreCabecalhoSoap->setAttribute('xmlns', 'http://www.gnre.pe.gov.br/wsdl/processar'); $gnreCabecalhoSoap->appendChild($gnre->createElement('versaoDados', '1.00')); $soapHeader = $gnre->createElement('soap12:Header'); $soapHeader->appendChild($gnreCabecalhoSoap); $soapEnv->appendChild($soapHeader); $gnre->appendChild($soapEnv); $gnreDadosMsg = $gnre->createElement('gnreDadosMsg'); $gnreDadosMsg->setAttribute('xmlns', 'http://www.gnre.pe.gov.br/webservice/GnreLoteRecepcao'); $gnreDadosMsg->appendChild($loteGnre); $soapBody = $gnre->createElement('soap12:Body'); $soapBody->appendChild($gnreDadosMsg); $soapEnv->appendChild($soapBody); return $gnre->saveXML(); }
private static function empty_news_xml($version, $encoding) { $newdoc = new DOMDocument($version, $encoding); /* rss wrapper section */ $root = $newdoc->createElement('rss'); $newdoc->appendChild($root); $version = $newdoc->createAttribute('version'); $version->appendChild($newdoc->createTextNode('2.0')); $root->appendChild($version); $channel = $newdoc->createElement('channel'); $root = $root->appendChild($channel); $title = $newdoc->createElement('title'); $channel->appendChild($title); $link = $newdoc->createElement('link'); $channel->appendChild($link); $link->appendChild($newdoc->createTextNode('http://web.mit.edu/newsoffice')); $description = $newdoc->createElement('description'); $channel->appendChild($description); return $newdoc; }
/** * This function is used to add quickly a DOMElement into another one * * @param DOMDocument $dom The xml document currently considered * @param DOMElement $nodeToAdd The dom element wherein the new dom node will be added * @param String $markupAndAttribute The specification of the new dom node * @param String $textContent Allow to add a textual content within the new node if needed * * Here is an inline example: * $newDomElement = xa($doc, $parentNode, 'newMarkupName'.xs.'param1=val1'.xs.'param2=val2', 'myTextContent'); * * @return DOMElement The reference to the new created dom element */ function &xa(&$dom, &$nodeToAdd, $markupAndAttribute, $textContent = '') { $tab = explode(xs, $markupAndAttribute); $markup = trim($tab[0]); unset($tab[0]); $attributes = array(); foreach ($tab as $attAndValue) { if (!empty($attAndValue)) { list($attName, $attValue) = explode('=', $attAndValue); $attributes[$attName] = $attValue; } } $markupElt = $dom->createElement($markup); if (is_array($attributes)) { foreach ($attributes as $name => $value) { $att = $dom->createAttribute($name); $markupElt->appendChild($att); $attValue = $dom->createTextNode($value); $att->appendChild($attValue); } } $nodeToAdd->appendChild($markupElt); if (!empty($textContent) || $textContent === '0') { $txt = $dom->createTextNode($textContent); $markupElt->appendChild($txt); } return $markupElt; }
function create_xml($data, $keys_array, $filename, $table_name) { $names = array('categories' => 'category', 'comp_orders' => 'comp_order', 'orders' => 'order', 'products' => 'product', 'statuses' => 'status', 'users' => 'user'); // Создаем DOM документ $xml = new DOMDocument('1.0', 'UTF-8'); $xml->formatOutput = true; // Создаем корневой элемент $loft_shop = $xml->createElement("loft_shop"); $xml->appendChild($loft_shop); // Создаем список $elements = $xml->createElement($table_name); $loft_shop->appendChild($elements); foreach ($data as $item) { // Создаем элемент списка $element = $xml->createElement($names[$table_name]); $id = $xml->createAttribute("id"); $id->value = $item['id']; // Устанавливаем атрибут id $element->appendChild($id); for ($i = 1; $i < count($keys_array); $i++) { $xml_field = $xml->createElement($keys_array[$i], $item[$keys_array[$i]]); $element->appendChild($xml_field); } $elements->appendChild($element); } $xml->save($filename); }
public function generateIndex() { // Create dom object $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->formatOutput = true; $dom->substituteEntities = false; // Create <urlset> root tag $sitemapindex = $dom->createElement('sitemapindex'); // Add attribute of urlset $xmlns = $dom->createAttribute('xmlns'); $sitemapindexText = $dom->createTextNode('http://www.sitemaps.org/schemas/sitemap/0.9'); $sitemapindex->appendChild($xmlns); $xmlns->appendChild($sitemapindexText); foreach ($this->generators as $generator) { $sitemap = $dom->createElement('sitemap'); $loc = $dom->createElement('loc'); $loc->appendChild($dom->createTextNode($generator->getWebFilePath())); $sitemap->appendChild($loc); $lastmod = $dom->createElement('lastmod'); $lastmod->appendChild($dom->createTextNode(date('Y-m-d'))); $sitemap->appendChild($lastmod); $sitemapindex->appendChild($sitemap); } $dom->appendChild($sitemapindex); return $dom->save($this->config['file_path']); }
private function createXML() { global $Site; global $dbPages; global $dbPosts; global $Url; $doc = new DOMDocument('1.0', 'UTF-8'); // Friendly XML code $doc->formatOutput = true; // Create urlset element $urlset = $doc->createElement('urlset'); $attribute = $doc->createAttribute('xmlns'); $attribute->value = 'http://www.sitemaps.org/schemas/sitemap/0.9'; $urlset->appendChild($attribute); // --- Base URL --- // Create url, loc and lastmod elements $url = $doc->createElement('url'); $loc = $doc->createElement('loc', $Site->url()); $lastmod = $doc->createElement('lastmod', ''); // Append loc and lastmod -> url $url->appendChild($loc); $url->appendChild($lastmod); // Append url -> urlset $urlset->appendChild($url); // --- Pages and Posts --- $all = array(); $url = trim($Site->url(), '/'); // --- Pages --- $filter = trim($Url->filters('page'), '/'); $pages = $dbPages->getDB(); unset($pages['error']); foreach ($pages as $key => $db) { $permalink = empty($filter) ? $url . '/' . $key : $url . '/' . $filter . '/' . $key; $date = Date::format($db['date'], DB_DATE_FORMAT, SITEMAP_DATE_FORMAT); array_push($all, array('permalink' => $permalink, 'date' => $date)); } // --- Posts --- $filter = rtrim($Url->filters('post'), '/'); $posts = $dbPosts->getDB(); foreach ($posts as $key => $db) { $permalink = empty($filter) ? $url . '/' . $key : $url . '/' . $filter . '/' . $key; $date = Date::format($db['date'], DB_DATE_FORMAT, SITEMAP_DATE_FORMAT); array_push($all, array('permalink' => $permalink, 'date' => $date)); } // Generate the XML for posts and pages foreach ($all as $db) { // Create url, loc and lastmod elements $url = $doc->createElement('url'); $loc = $doc->createElement('loc', $db['permalink']); $lastmod = $doc->createElement('lastmod', $db['date']); // Append loc and lastmod -> url $url->appendChild($loc); $url->appendChild($lastmod); // Append url -> urlset $urlset->appendChild($url); } // Append urlset -> XML $doc->appendChild($urlset); $doc->save(PATH_PLUGINS_DATABASES . $this->directoryName . DS . 'sitemap.xml'); }
/** * Adds an attribute to the XML node $node. * * @param DOMNode $node The node to add the attribute to * @param string $attribute The name of the attribute to add * @param mixed $value The value of the attribute * @ignore */ protected function addAttribute(DOMNode $node, $attribute, $value) { $attr = $this->xml->createAttribute($attribute); $val = $this->xml->createTextNode($value); $attr->appendChild($val); $node->appendChild($attr); }
protected function createDOM(AgaviRequestDataHolder $rd) { $results = $rd->getParameter("searchResult", null); $count = $rd->getParameter("searchCount"); $DOM = new DOMDocument("1.0", "UTF-8"); $root = $DOM->createElement("results"); $DOM->appendChild($root); foreach ($results as $result) { $resultNode = $DOM->createElement("result"); $root->appendChild($resultNode); foreach ($result as $fieldname => $field) { $node = $DOM->createElement("column"); $node->nodeValue = $field; $name = $DOM->createAttribute("name"); $name->nodeValue = $fieldname; $node->appendChild($name); $resultNode->appendChild($node); } } if ($count) { $count = array_values($count[0]); $node = $DOM->createElement("total"); $node->nodeValue = $count[0]; $root->appendChild($node); } return $DOM; }
function createRss() { $dom = new DOMDocument("1.0", "utf-8"); $dom->formatOutput = true; $dom->preserveWhiteSpace = false; $rss = $dom->createElement("rss"); $dom->appendChild($rss); $version = $dom->createAttribute("version"); $version->value = '2.0'; $rss->appendChild($version); $channel = $dom->createElement("channel"); $rss->appendChild($channel); $title = $dom->createElement("title", self::RSS_TITLE); $channel->appendChild($title); $link = $dom->createElement("link", self::RSS_LINK); $channel->appendChild($link); $items = $this->getNews(); foreach ($items as $item) { $rssItem = $dom->createElement("item"); $nTitle = $dom->createElement("title", $item["title"]); $nLink = $dom->createElement("link", $item["source"]); $nDesc = $dom->createElement("description", $item["description"]); $nPub = $dom->createElement("pubYear", $item["datetime"]); $nCategory = $dom->createElement("category", $item["category"]); $rssItem->appendChild($nTitle); $rssItem->appendChild($nLink); $rssItem->appendChild($nDesc); $rssItem->appendChild($nPub); $rssItem->appendChild($nCategory); $channel->appendChild($rssItem); } $dom->save(self::RSS_NAME); }
function create_xml($table, $conn) { //получаем названия столбцов $fields = get_fields($table, $conn); //получаем данные $data_from_table = get_data($table, $conn); //создаем объект документа $dom = new DOMDocument('1.0', 'UTF-8'); //создаем корневой элемент по имени таблицы $catalog = $dom->createElement("catalog"); $dom->appendChild($catalog); //создаем контейнер для обектов $entities = $dom->createElement("entities"); $catalog->appendChild($entities); //создаем и добавляем объекты foreach ($data_from_table as $value) { $entity = $dom->createElement("entity"); $attribute_id = $dom->createAttribute('id'); $attribute_id->value = $value[0]; $entity->appendChild($attribute_id); for ($k = 0, $i = count($fields); $k < $i; $k++) { $name_tag = $dom->createElement($fields[$k], $value[$k]); $entity->appendChild($name_tag); } $entities->appendChild($entity); } //сохраняем документ $dom->save("files/xml/" . $table . ".xml"); }
/** * 生成DOMElement树 * array( * 'tagName'=>'Shanghai', // 标签名称 * 'nodeValue'=>'', // 标签值,可选 * 'attributeArr'=>array(), // 属性值, 可选 * 'subElementArr'=>array( // 子节点,跟父类数据结构一样,可选 * array( * 'tagName'=>'Hongkou', * 'nodeValue'=>'Hongkou nodeValue', * 'attributeArr'=>array('lng'=>'100', 'lat'=>'300'), * 'subElementArr'=>array(), * ), * array( * 'tagName'=>'Xuhui', * 'nodeValue'=>'Xuhui nodeValue', * 'attributeArr'=>array('lng'=>'200', 'lat'=>'400'), * 'subElementArr'=>array(), * ), * ), * ); * @param DOMDocument $DOMDocument 用于生成中间环节的DOMElement,DOMText,DOMAttr等,直接new DOMElement会出现不可写的报错 * @param Array $arr */ public static function DOMElement(DOMDocument $DOMDocument, $arr) { $DOMElement = $DOMDocument->createElement($arr['tagName']); $DOMDocument->appendChild($DOMElement); if (!empty($arr['nodeValue'])) { // 如果存在节点文本,则添加该文本 $textNode = $DOMDocument->createTextNode($arr['nodeValue']); $DOMElement->appendChild($textNode); } if (!empty($arr['attributeArr'])) { // 如果存在属性,则循环为当前标签添加属性 foreach ($arr['attributeArr'] as $k => $v) { $attribute = $DOMDocument->createAttribute($k); $attribute->appendChild($DOMDocument->createTextNode($v)); $DOMElement->appendChild($attribute); } } if (!empty($arr['subElementArr'])) { // 如果存在子节点,则循环追加子节点 foreach ($arr['subElementArr'] as $subElement) { $DOMElement->appendChild(self::DOMElement($DOMDocument, $subElement)); } } return $DOMElement; }
/** * Añadir un nuevo nodo al árbol raíz * * @param \DOMElement $node El nodo a añadir * @throws SPException */ private function appendNode(\DOMElement $node) { try { // Si se utiliza clave de encriptación los datos se encriptan en un nuevo nodo: // Encrypted -> Data if ($this->_encrypted === true) { // Obtener el nodo en formato XML $nodeXML = $this->_xml->saveXML($node); // Crear los datos encriptados con la información del nodo $encrypted = Crypt::mkEncrypt($nodeXML, $this->_exportPass); $encryptedIV = Crypt::$strInitialVector; // Buscar si existe ya un nodo para el conjunto de datos encriptados $encryptedNode = $this->_root->getElementsByTagName('Encrypted')->item(0); if (!$encryptedNode instanceof \DOMElement) { $encryptedNode = $this->_xml->createElement('Encrypted'); } // Crear el nodo hijo con los datos encriptados $encryptedData = $this->_xml->createElement('Data', base64_encode($encrypted)); $encryptedDataIV = $this->_xml->createAttribute('iv'); $encryptedDataIV->value = base64_encode($encryptedIV); // Añadir nodos de datos $encryptedData->appendChild($encryptedDataIV); $encryptedNode->appendChild($encryptedData); // Añadir el nodo encriptado $this->_root->appendChild($encryptedNode); } else { $this->_root->appendChild($node); } } catch (\DOMException $e) { throw new SPException(SPException::SP_WARNING, $e->getMessage(), __FUNCTION__); } }
public function test__recursive_force_closing_tags__ignore_non_elements() { $dom = new DOMDocument(); $node = $dom->createAttribute('src'); $expected = ' src=""'; $actual = AMP_DOM_Utils::recursive_force_closing_tags($dom, $node); $this->assertEquals($expected, $dom->saveXML($node)); }
/** * * Create new attribute * @param string $name * @param string $value * @return DOMAttr */ public function create_attribute($name, $value = null) { $result = $this->doc->createAttribute($name); if (!is_null($value)) { $result->nodeValue = $value; } return $result; }
public function insert($text) { switch ($this->type) { case self::LOG: if ($this->dated) { $date = "_" . str_replace(" ", "_", $this->date); $append = null; } else { $date = ""; $append = $this->clear ? null : FILE_APPEND; if ($this->backup) { $result = copy($this->path . $this->filename . "." . $this->type, $this->path . $this->filename . "_" . str_replace(" ", "_", $this->date) . "-backup." . $this->type) ? 1 : 0; $append = $result ? $result : FILE_APPEND; } } $log = $this->date . " [ip] " . $this->ip . " [text] " . $text . PHP_EOL; $result = file_put_contents($this->path . $this->filename . $date . "." . $this->type, $log, $append) ? 1 : 0; break; case self::XML: $xml = new \DOMDocument('1.0', 'UTF-8'); if ($this->clear) { if ($clear) { $result = copy($this->path . $this->filename . "." . $this->type, $this->path . $this->filename . "_" . str_replace(" ", "_", $this->date) . "-backup." . $this->type) ? 1 : 0; } $root = $xml->createElement('data'); $root = $xml->appendChild($root); } else { $this->check_file_available($this->type); $xml->load($this->path . $this->filename . "." . $this->type); } $root = $xml->getElementsByTagName('data')->item(0); $log = $xml->createElement('log', $text); $log = $root->appendChild($log); $date = $xml->createAttribute('date'); $date->appendChild($xml->createTextNode($this->date)); $ip = $xml->createAttribute('ip'); $ip->appendChild($xml->createTextNode($this->ip)); $log->appendChild($date); $log->appendChild($ip); $xml->formatOutput = true; $xml->saveXML(); $result = $xml->save($this->path . $this->filename . "." . $this->type) ? 1 : 0; break; } return $result; }