function addModel($node) { $document = new domDocument("1.0", "utf-8"); $document->load("test3.xml"); if ($node == "telefon") { $nameEl = "Телефон"; } if ($node == "noutbuk") { $nameEl = "Ноутбук"; } if ($node == "printer") { $nameEl = "Принтер"; } if ($_POST["marka"] != "" && $_POST["year"] != "") { $element = $document->getElementsByTagName($node)->item(0); $model = $document->createElement("model"); $element->appendChild($model); $name = $document->createElement("name", $_POST["marka"]); $model->appendChild($name); $year = $document->createElement("year", $_POST["year"]); $model->appendChild($year); $document->save("test3.xml"); echo "<p style='padding:10px; background:#C3FFD2;'>" . $nameEl . " Удачно добавлен!</p>"; } else { echo "<p style='padding:10px; background:#FFF0F0;'>Не удалось добавить " . $nameEl . ", так как не все поля были заполнены!</p>"; } }
public function addUser(){ $document = new domDocument(); $document->load("users/users.xml"); $root = $document->getElementsByTagName("users")->item(0); $user = $root->appendChild(new domElement("user")); $user->appendChild($document->createElement("login", "$this->login")); $user->appendChild($document->createElement("password","$this->pass")); $document->save("users/users.xml"); }
/** * Adds an child element to the parent * @param string The name element * @param domNode * @return domNode */ private function addElement($name, $parent = false, $ns = false) { if ($ns) { $el = $this->doc->createElementNS($ns, $name); } else { $el = $this->doc->createElement($name); } if ($parent) { $parent->appendChild($el); } return $el; }
public function actionGetUserNotify($email) { header("Content-Type: text/xml"); $performer = 9; $notify = Notify::model()->findAll(array('condition' => 'performer_id=:performer_id', 'limit' => '3', 'params' => array(':performer_id' => $performer))); $dom = new domDocument("1.0", "cp1251"); // Создаём XML-документ версии 1.0 с кодировкой utf-8 $root = $dom->createElement("notifys"); // Создаём корневой элемент $dom->appendChild($root); foreach ($notify as $n) { $notify = $dom->createElement("notify"); $header = $dom->createElement("header", $n->header); $description = $dom->createElement("description", strip_tags($n->description)); $link = $dom->createElement("link", Notify::getCreateXmlUrl($n->route, $n->route_params)); $notify->appendChild($header); $notify->appendChild($description); $notify->appendChild($link); $root->appendChild($notify); } $import = simplexml_import_dom($dom); echo $import->asXML(); }
/** * Get XML by Array * * @param array $ar * @param array $options [] * root_tag - root tag wraping body xml (example root - <root>...</root>) * format - true/false (formatting output XML) * version - XML version (<?xml version="1"?>) * encode - XML encode (<?xml encode="UTF-8"?>) * nohead - XML output without "<?xml" header * * @return string */ public static function createXML(array $ar, $options = array()) { $root_tag = isset($options['root_tag']) ? $options['root_tag'] : 'root'; $format = isset($options['format']) ? $options['format'] : true; $version = isset($options['version']) ? $options['version'] : '1.0'; $encode = isset($options['encode']) ? $options['encode'] : 'UTF-8'; $nohead = isset($options['nohead']) ? $options['nohead'] : false; $dom = new domDocument($version, $encode); $root = $dom->appendChild($dom->createElement($root_tag)); self::createXMLElement($dom, $root, $ar); $dom->formatOutput = $format; if ($nohead) { return $dom->saveXML($root); } return $dom->saveXML(); }
/** * * @get text between tags * @param string $tag The tag name * @param string $html The XML or XHTML string * @param int $strict Whether to use strict mode * @param string $encoding * @return array */ private function getTextBetweenTags($tag, $html, $strict = 0, $encoding = "UTF-8") { global $PAGE, $CFG; if (!isset($CFG->filter_jsxgraph_divid)) { set_config('filter_jsxgraph_divid', 'box'); } if (!isset($CFG->filter_jsxgraph_boardvar)) { set_config('filter_jsxgraph_boardvar', 'board'); } if (!isset($CFG->filter_jsxgraph_width)) { set_config('filter_jsxgraph_width', '500'); } if (!isset($CFG->filter_jsxgraph_height)) { set_config('filter_jsxgraph_height', '400'); } // a new dom object $dom = new domDocument(); $dom->formatOutput = true; // load the html into the object if ($strict == 1) { $dom->loadXML($html); } else { libxml_use_internal_errors(true); $htmlutf8 = mb_convert_encoding($html, 'HTML-ENTITIES', $encoding); $dom->loadHTML($htmlutf8); libxml_use_internal_errors(false); } // discard white space $dom->preserveWhiteSpace = false; $dom->strictErrorChecking = false; $dom->recover = true; // the tag by its tag name $content = $dom->getElementsByTagname($tag); if (count($content) > 0) { $PAGE->requires->js(new moodle_url($CFG->wwwroot . '/filter/jsxgraph/jsxgraphcore.js')); } // Iterate backwards through the jsxgraph tags $i = $content->length - 1; while ($i > -1) { $item = $content->item($i); // Read attributes $w = $item->getAttribute('width'); if ($w == "") { $w = $CFG->filter_jsxgraph_width; } $h = $item->getAttribute('height'); if ($h == "") { $h = $CFG->filter_jsxgraph_height; } $b = $item->getAttribute('box'); if ($b == "") { $b = $CFG->filter_jsxgraph_divid . $i; } $brd = $item->getAttribute('board'); if ($brd == "") { $brd = $CFG->filter_jsxgraph_boardvar . $i; } /* Create new div element containing JSXGraph */ $out = $dom->createElement('div'); $a = $dom->createAttribute('id'); $a->value = $b; $out->appendChild($a); $a = $dom->createAttribute('class'); $a->value = "jxgbox"; $out->appendChild($a); $a = $dom->createAttribute('style'); $a->value = "width:" . $w . "px; height:" . $h . "px; "; $out->appendChild($a); $t = $dom->createTextNode(""); $out->appendChild($t); $out = $dom->appendChild($out); // Replace <jsxgraph> by <div> $item->parentNode->replaceChild($out, $item); $code = ""; $needGXT = false; $url = $item->getAttribute('file'); if ($url != "") { $code = "var " . $brd . " = JXG.JSXGraph.loadBoardFromFile('" . $b . "', '" . $url . "', 'Geonext');"; $needGXT = true; } else { $url = $item->getAttribute('filestring'); if ($url != "") { $code = "var " . $brd . " = JXG.JSXGraph.loadBoardFromString('" . $b . "', '" . $url . "', 'Geonext');"; $needGXT = true; } else { // Plain JavaScript code $code = $item->nodeValue; } } // Place JavaScript code at the end of the page. $PAGE->requires->js_init_call($code); if ($needGXT) { $PAGE->requires->js(new moodle_url($CFG->wwwroot . '/filter/jsxgraph/GeonextReader.js')); } --$i; } // remove DOCTYPE $dom->removeChild($dom->firstChild); // remove <html><body></body></html> //$dom->replaceChild($dom->firstChild->firstChild->firstChild, $dom->firstChild); //return $dom->saveXML(); $str = $dom->saveHTML(); $str = str_replace("<body>", "", $str); $str = str_replace("</body>", "", $str); $str = str_replace("<html>", "", $str); $str = str_replace("</html>", "", $str); return $str; }
protected function xml($datafeed, $filename) { $this->load->helper('download'); $dom = new domDocument("1.0", "utf-8"); $root = $dom->createElement("items"); $dom->appendChild($root); foreach ($datafeed as $feed) { if ($feed->ic_id == "") { continue; } $feed->ic_retail_price = trim($feed->ic_retail_price) == '' || $feed->ic_retail_price == 0 ? $feed->ic_price * 3 : $feed->ic_retail_price; $item = $dom->createElement("item"); $item->setAttribute("id", $feed->ic_id); $params = array(); $params['SKU'] = $dom->createElement("SKU", $feed->SKU); $params['Barcode'] = $dom->createElement("Barcode", $feed->upc_ean); $params['Manufacturer_Part_Number'] = $dom->createElement("Manufacturer_Part_Number", $feed->manuf_num); $params['Manufacturer_Name'] = $dom->createElement("Manufacturer_Name", $feed->m_name); $params['Brand_Name'] = $dom->createElement("Brand_Name", $feed->b_name); $params['Title'] = $dom->createElement("Title", $feed->tr_title); $params['Description'] = $dom->createElement("Description", htmlspecialchars(strip_tags($feed->tr_desc))); $params['Category_ID'] = $dom->createElement("Category_ID", $feed->c_id); $params['Category_Name'] = $dom->createElement("Category_Name", htmlspecialchars($this->getFullCategoryName($feed->c_id))); $params['Weight'] = $dom->createElement("Weight", $feed->weight + " " + $feed->weightScale); $params['Ship_Alone'] = $dom->createElement("Ship_Alone", $feed->ship_alone); $params['Height'] = $dom->createElement("Height", $feed->d_height + " " + $feed->d_scale); $params['Width'] = $dom->createElement("Width", $feed->d_width + " " + $feed->d_scale); $params['Depth'] = $dom->createElement("Depth", $feed->d_dept + " " + $feed->d_scale); $params['LeadTime'] = $dom->createElement("LeadTime", $feed->ic_leadtime); $params['Quantity_In_Stock'] = $dom->createElement("Quantity_In_Stock", $feed->ic_quan); $params['Selling_Price'] = $dom->createElement("Selling_Price", $feed->ic_price); $params['MSRP'] = $dom->createElement("MSRP", $feed->ic_retail_price); $params['Promo_Text'] = $dom->createElement("Promo_Text", $feed->ic_prom_text); $params['MAP'] = $dom->createElement("MAP", $feed->ic_map); $params['Shipping_Cost'] = $dom->createElement("Shipping_Cost", $feed->ic_ship_cost); $params['Min_Order'] = $dom->createElement("Min_Order", $feed->ic_min_order); $params['Case_Pack'] = $dom->createElement("Case_Pack", $feed->ic_case_pack); $this->load->model('inventories'); $image_list = $this->inventories->list_image($feed->i_id); $images = $dom->createElement("images"); foreach ($image_list as $image) { $pic_name = $dom->createElement("image", "http://shop.oceantailer.com/" . $image->ii_link); $images->appendChild($pic_name); } foreach ($params as $param) { $item->appendChild($param); } $item->appendChild($images); $root->appendChild($item); } $dom->save($filename); return; }
$day[$count] = $attr4[$count]['day']; $low[$count] = $attr4[$count]['low']; $high[$count] = $attr4[$count]['high']; $text1[$count] = $attr4[$count]['text']; //echo "result here".$day[$count]; $count++; } } /************************************************create xml********************************************/ try { /*** a new dom object ***/ $dom = new domDocument(); /*** make the output tidy ***/ $dom->formatOutput = true; /*** create the root element ***/ $root = $dom->appendChild($dom->createElement("weather")); /*** create the simple xml element ***/ $sxe = simplexml_import_dom($dom); /*** add a feed element ***/ $sxe->addChild("feed", $url_weather); /*** add a link element ***/ $sxe->addChild("link", $link); /*** add a location element ***/ $loc = $sxe->addChild("location"); /*** add attributes ***/ $loc->addAttribute("city", $city); $loc->addAttribute("region", $region); $loc->addAttribute("country", $country); /*** add a unit element***/ $uni = $sxe->addChild("units"); /*** add attributes ***/
<?php $dom = new domDocument('1.0'); $dom->load(dirname(__FILE__) . "/thedata.xml"); $new_item = $dom->createElement('item'); $new_item->setAttribute("id", 1234); // set attribute id for new item foreach (array('title', 'link', 'description') as $v) { $node = $dom->createElement($v); $node->appendChild($dom->createTextNode($v)); $new_item->appendChild($node); } // append entry to existing forum entries $dom->documentElement->appendChild($new_item); $xml = $dom->saveXML(); echo nl2br(htmlspecialchars(str_replace('><', ">\n<", $xml)));
<?php error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING); $dom = new domDocument("1.0", "utf-8"); // Создаём XML-документ версии 1.0 с кодировкой utf-8 $root = $dom->createElement("rss"); // Создаём корневой элемент $root->setAttribute("version", "2.0"); $dom->appendChild($root); $chanel = $dom->createElement("channel"); $dom->appendChild($chanel); $root->appendChild($chanel); $title = $dom->createElement("title", "Лента сайта WEIRD WORLD"); $dom->appendChild($title); $chanel->appendChild($title); $link = $dom->createElement("link", "http://weird-world.ru"); $dom->appendChild($link); $chanel->appendChild($link); $description = $dom->createElement("description", "Описание"); $dom->appendChild($description); $chanel->appendChild($description); include "../include/connection.php"; $result = mysql_query("SELECT * FROM articles WHERE visible='1'", $db); if (mysql_num_rows($result) > 0) { do { $item = $dom->createElement("item"); $dom->appendChild($item); $chanel->appendChild($item); $title = $dom->createElement("title", htmlspecialchars_decode($row["title"])); $dom->appendChild($title); $item->appendChild($title);
<bureau> \t<userburo> \t</userburo> </bureau> XML; $dom = new domDocument(); $dom->loadXML($xmlPrefs); if (!$dom) { echo 'Erreur de traitement XML'; exit; } $frstN = array("wallpaper", "pos_wallpaper", "iconsize", "iconsfield", "bgcolor", "quicklaunch", "s_idart", "winsize", "data"); $liste = $dom->getElementsByTagName('userburo'); $neud = $liste->item(0); foreach ($frstN as $thisN) { ${$thisN} = $dom->createElement($thisN); ${$thisN}->appendChild($dom->createTextNode($_POST[$thisN])); $neud->appendChild(${$thisN}); } foreach ($_POST['icons'] as $k => $val) { $noeud = $liste->item(0); $node = $dom->createElement("icon"); foreach ($val as $k1 => $val1) { $icon_x = $dom->createElement($k1, $val1); $node->appendchild($icon_x); } $noeud->appendChild($node); } $s = simplexml_import_dom($dom); // ecriture du fichier $filexml = 'PREFS_' . $login . '.xml';
<?php include '../Config/db.php'; header("content-type: text/xml"); $dom = new domDocument("1.0", "CP1251"); $root = $dom->createElement("Orders"); $dom->appendChild($root); $query = mysql_query(@"SELECT\n orders.*,\n users.name,\n users.email,\n users.phone,\n users.company,\n warehouses.keycode AS wh_key,\n pricetypes.keycode AS pt_key\n FROM orders\n LEFT JOIN users ON orders.user_id = users.id\n LEFT JOIN warehouses ON users.wh_id = warehouses.id\n LEFT JOIN pricetypes ON users.pt_id = pricetypes.id\n WHERE orders.status = 1 AND orders.sync = 0"); while ($do = mysql_fetch_array($query)) { $order = $dom->createElement("Order"); $number = $dom->createElement("Number", $do['id']); $wh = $dom->createElement("WH", $do['wh_key']); $pt = $dom->createElement("PT", $do['pt_key']); $clientID = $dom->createElement("ClientID", $do['user_id']); $clientName = $dom->createElement("ClientName", $do['name']); $clientCompany = $dom->createElement("Company", $do['company']); $email = $dom->createElement("Email", $do['email']); $phone = $dom->createElement("Phone", $do['phone']); $comment = $dom->createElement("Comment", $do['comment']); $products = $dom->createElement("Products"); $pquery = mysql_query("SELECT cart.*, products.keycode, categories.expected FROM cart LEFT JOIN products ON cart.product_id = products.id LEFT JOIN categories ON products.category_id = categories.id WHERE order_id = '" . $do['id'] . "'"); while ($pdo = mysql_fetch_array($pquery)) { $product = $dom->createElement("Product"); $article = $dom->createElement("Key", $pdo['keycode']); $quantity = $dom->createElement("Quantity", $pdo['quantity']); $price = $dom->createElement("Price", $pdo['price']); $expected = $dom->createElement("ThisExpected", $pdo['expected']); $product->appendChild($article); $product->appendChild($quantity); $product->appendChild($price); $product->appendChild($expected);
</SET_OF_SOLUTIONS> <SET_OF_RELATED_PATTERNS> </SET_OF_RELATED_PATTERNS> <PATTERN_IDENTIFICATION> </PATTERN_IDENTIFICATION> </Patern>'; $doc = new domDocument(); $doc->loadXML($anXMLString); $key = key($resultQuery); $val = current($resultQuery); $nbrValues = count($resultQuery); while (list($key, $val) = each($resultQuery)) { if (!is_array($val)) { switch ($key) { case $key == 'pattern_name': $newnode = $doc->createElement($key, $val); $doc->appendChild($newnode); $add = $doc->getElementsByTagName('GENERAL')->item(0); $add->appendChild($newnode); break; case $key == 'pattern_abstract': $newnode = $doc->createElement($key, $val); $doc->appendChild($newnode); $add = $doc->getElementsByTagName('GENERAL')->item(0); $add->appendChild($newnode); break; case $key == 'pattern_desc': $newnode = $doc->createElement($key, $val); $doc->appendChild($newnode); $add = $doc->getElementsByTagName('GENERAL')->item(0); $add->appendChild($newnode);
public static function remove($subscriber, $subscriberId, $cle = '') { $db = JFactory::getDBO(); $listUnsubA = array(); //unsubscribe listIds $allAvailableListsA = JRequest::getVar('sub_list_id', ''); $unsubListValA = JRequest::getVar('unsubscribed', ''); $textarea_msg = JRequest::getVar('textareamess', ' ', 'post'); foreach ($allAvailableListsA as $key => $unsublist) { if (!empty($unsubListValA[$key]) == 1) { $listidUnsubA[] = $unsublist; } } if (!empty($subscriberId) and !empty($cle)) { if (md5($subscriber->email) == $cle) { if (!empty($listidUnsubA)) { $query = 'UPDATE `#__jnews_listssubscribers` SET '; $query .= ' `unsubdate`=' . time(); $query .= ' ,`unsubscribe`=1'; $query .= ' WHERE `subscriber_id`= ' . $subscriberId; $query .= ' AND `list_id` IN (' . implode(',', $listidUnsubA) . ')'; $db->setQuery($query); $result = $db->query(); $query = 'SELECT * FROM `#__jnews_lists` WHERE `id` IN (' . implode(',', $listidUnsubA) . ')'; $db->setQuery($query); $listsO = $db->loadObjectList(); } //check if we have subscription to any auto-responder $query = 'SELECT `id` FROM `#__jnews_lists` '; $query .= ' WHERE `list_type`= 2 '; $query .= ' AND `id` IN (' . implode(',', $listidUnsubA) . ')'; $db->setQuery($query); $loadResultArray = $db->loadObjectList(); $autoRespondListA = jnews::convertObjectList2Array($loadResultArray); if (!empty($autoRespondListA)) { $query = 'DELETE FROM `#__jnews_queue` '; $query .= ' WHERE `subscriber_id`= ' . $subscriberId; $query .= ' AND `mailing_id` IN ( SELECT `mailing_id` FROM `#__jnews_listmailings` WHERE `list_id` IN (' . implode(',', $autoRespondListA) . ') )'; $db->setQuery($query); $db->query(); } foreach ($listsO as $key => $list) { //we send the unsubscription notification to the subscriber if it is turn to yes if ($list->unsubscribesend == 1) { jNews_ProcessMail::sendUnsubcribeEmail($subscriber, $subscriberId, $list); } //we send the unsubscription notification to the list owner if it is turn to yes if ($GLOBALS[JNEWS . 'level'] > 2 && $list->unsubscribenotifyadmin == 1 && !empty($list->notifyadminmsg) && !empty($list->owner)) { $my = JFactory::getUser($list->owner); if ($list->notifyadminmsg != "") { $dom = new domDocument(); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; if ($dom->loadHTML("<html><body>" . $list->notifyadminmsg . "</body></html>")) { $xpath = new DOMXpath($dom); $elements = $xpath->query("/html/descendant::*[contains(text(),'LISTNAME')]/.."); if (!is_null($elements)) { $feedback = _JNEWS_UNSUBSCRIBE_MESSAGE_TEXTAREA_TITLE; foreach ($elements as $element) { $item = $dom->createElement("span", " " . $feedback); $br = $dom->createElement('br'); $item->insertBefore($br); $titlespace = $dom->createElement("span", " " . $textarea_msg); $item->appendChild($titlespace); if ($element->nextSibling != null) { $appen = $element->nextSibling; } else { $appen = $element; } if ($element->parentNode != null) { $inss = $element->parentNode; } else { $inss = $element; } $inss->insertBefore($item, $appen); } $dom->formatOutput = true; $lisnotifyadminmsg = $dom->saveHTML(); } $res_search = preg_match("/(?:<body[^>]*>)(.*)<\\/body>/isU", $lisnotifyadminmsg, $matches); if ($res_search > 0 && isset($matches[1]) && $matches[1] !== "") { $list->notifyadminmsg = $matches[1]; } } } } jNews_ProcessMail::sendNotification($list->notifyadminmsg, $subscriber, $my, $list, JNEWS_SITE_NAME . ' ' . _JNEWS_UNSUBS_NOTIFYSUBJECT); } if (!empty($GLOBALS[JNEWS . 'unsubscribe_notification'])) { $listOfAdminA = explode(',', $GLOBALS[JNEWS . 'unsubscribe_notification']); if (!empty($listOfAdminA)) { foreach ($listOfAdminA as $oneAdmin) { if (empty($oneAdmin)) { continue; } $owner = new stdClass(); $owner->name = $oneAdmin; $owner->email = $oneAdmin; jNews_ProcessMail::sendNotification(_JNEWS_UNSUBSCRIBE_ADMIN_NOTIFICATION, $newSubscriber, $owner, $list, JNEWS_SITE_NAME . ' ' . _JNEWS_UNSUBS_NOTIFYSUBJECT); } } } } } return $result; }
public function calculate() { $weight = $this->getTotalWeight() > 0 ? $this->getTotalWeight() : $this->avg_weight; $city = $this->getAddress('city') . ', ' . $this->getAddress('region'); if ($city == '') { $services = 'Не задан город'; return $services; } if (!extension_loaded('curl')) { $services = 'PHP extension CURL not loaded'; return $services; } $dom = new domDocument("1.0", "utf-8"); $root = $dom->createElement("request"); $dom->appendChild($root); $child = $dom->createElement("function", "get_delivery_price"); $root->appendChild($child); $child = $dom->createElement("api_id", $this->api_id); $root->appendChild($child); $child = $dom->createElement("from_city", $this->from_city_code_id); $root->appendChild($child); $child = $dom->createElement("to_city", $city); $root->appendChild($child); $child = $dom->createElement("pickup_place", 0); $root->appendChild($child); $child = $dom->createElement("weight", $weight); $root->appendChild($child); $child = $dom->createElement("order_price", $this->getTotalPrice()); $root->appendChild($child); $child = $dom->createElement("num", $this->avg_num); $root->appendChild($child); $child = $dom->createElement("tarifs_type", 1); $root->appendChild($child); $child = $dom->createElement("price_options", 1); $root->appendChild($child); $child = $dom->createElement("delivery_partner", $this->partner); $root->appendChild($child); $res = $this->sendRequest($dom->saveXML()); try { $xml = new SimpleXMLElement($res); } catch (Exception $e) { return 'Ошибка получения данных'; } $price = (double) $xml->price; if ($xml->error_code > 0) { return "В заданный город доставка не осуществляется"; } if ($xml->srok_dostavki != '') { $srok_dostavki = $xml->srok_dostavki . ' дн.'; } $services['sl_courier'] = array('name' => 'до дверей', 'description' => '', 'id' => 'sl_courier', 'est_delivery' => $srok_dostavki, 'rate' => $price, 'currency' => 'RUB'); return $services; }
print "valid\n"; } catch (Exception $e) { print $e->getMessage() . "\n"; } print " 3 DOMDocument::createElement(' ')\n"; try { $dom = new domDocument(); $dom->createElement(' '); print "valid\n"; } catch (Exception $e) { print $e->getMessage() . "\n"; } print " 4 DOMDocument::createElement('prefix:valid')\n"; try { $dom = new domDocument(); $dom->createElement('prefix:valid'); print "valid\n"; } catch (Exception $e) { print $e->getMessage() . "\n"; } print " 5 DOMDocument::createElementNS('http://valid.com', 'valid')\n"; try { $dom = new domDocument(); $dom->createElementNS('http://valid.com', 'valid'); print "valid\n"; } catch (Exception $e) { print $e->getMessage() . "\n"; } print " 6 DOMDocument::createElementNS('http://valid.com', 'prefix:valid')\n"; try { $dom = new domDocument();
public function request($arg) { $site = litepublisher::$site; $s = '<?php turlmap::sendxml(); ?>'; switch ($arg) { case 'manifest': $s .= '<manifest xmlns="http://schemas.microsoft.com/wlw/manifest/weblog">' . '<options>' . '<clientType>WordPress</clientType>' . '<supportsKeywords>Yes</supportsKeywords>' . '<supportsGetTags>Yes</supportsGetTags>' . '<supportsNewCategories>Yes</supportsNewCategories>' . '</options>' . '<weblog>' . '<serviceName>Lite Publisher</serviceName>' . "<homepageLinkText>{$site->name}</homepageLinkText>" . "<adminLinkText>{$site->name}</adminLinkText>" . "<adminUrl>{$site->url}/admin/</adminUrl>" . '<postEditingUrl>' . "<![CDATA[{$site->url}/admin/posts/editor/{$site->q}id={post-id}]]>" . '</postEditingUrl>' . '</weblog>' . '<buttons>' . '<button>' . '<id>0</id>' . '<text>Manage Comments</text>' . '<imageUrl>/favicon.ico</imageUrl>' . '<clickUrl>' . "<![CDATA[{$site->url}/admin/comments/]]>" . '</clickUrl>' . '</button>' . '</buttons>' . '</manifest>'; break; case 'rsd': /* $s .= '<rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd">' . '<service>' . '<engineName>Lite Publisher</engineName>' . '<engineLink>http://litepublisher.com/</engineLink>' . "<homePageLink>$site->url/</homePageLink>" . '<apis>' . '<api name="WordPress" blogID="1" preferred="true" apiLink="' . $site->url . '/rpc.xml" />' . '<api name="Movable Type" blogID="1" preferred="false" apiLink="' . $site->url . '/rpc.xml" />' . '<api name="MetaWeblog" blogID="1" preferred="false" apiLink="' . $site->url . '/rpc.xml" />' . '<api name="Blogger" blogID="1" preferred="false" apiLink="' . $site->url . '/rpc.xml" />' . '</apis>' . '</service>' . '</rsd>'; */ $dom = new domDocument(); $dom->encoding = 'utf-8'; $rsd = $dom->createElement('rsd'); $dom->appendChild($rsd); tnode::attr($rsd, 'version', '1.0'); tnode::attr($rsd, 'xmlns', 'http://archipelago.phrasewise.com/rsd'); $service = tnode::add($rsd, 'service'); tnode::addvalue($service, 'engineName', 'LitePublisher'); tnode::addvalue($service, 'engineLink', 'http://litepublisher.com/'); tnode::addvalue($service, 'homePageLink', litepublisher::$site->url . '/'); $apis = tnode::add($service, 'apis'); $api = tnode::add($apis, 'api'); tnode::attr($api, 'name', 'WordPress'); tnode::attr($api, 'blogID', '1'); tnode::attr($api, 'preferred', 'true'); tnode::attr($api, 'apiLink', litepublisher::$site->url . '/rpc.xml'); $api = tnode::add($apis, 'api'); tnode::attr($api, 'name', 'Movable Type'); tnode::attr($api, 'blogID', '1'); tnode::attr($api, 'preferred', 'false'); tnode::attr($api, 'apiLink', litepublisher::$site->url . '/rpc.xml'); $api = tnode::add($apis, 'api'); tnode::attr($api, 'name', 'MetaWeblog'); tnode::attr($api, 'blogID', '1'); tnode::attr($api, 'preferred', 'false'); tnode::attr($api, 'apiLink', litepublisher::$site->url . '/rpc.xml'); $api = tnode::add($apis, 'api'); tnode::attr($api, 'name', 'Blogger'); tnode::attr($api, 'blogID', '1'); tnode::attr($api, 'preferred', 'false'); tnode::attr($api, 'apiLink', litepublisher::$site->url . '/rpc.xml'); $xml = $dom->saveXML(); $s .= substr($xml, strpos($xml, '?>') + 2); break; } return $s; }
public function generateRss() { $xml_par = $this->getXml(); $xml_version = $xml_par['version']; $xml_charset = $xml_par['charset']; $xml = new domDocument($xml_version, $xml_charset); $rss = $xml->createElement('rss'); //rss foreach ($this->getRss() as $key => $value) { $rss->setAttribute($key, $value); } $xml->appendChild($rss); //channel $channel = $xml->createElement('channel'); foreach ($this->channel as $key => $value) { $row = $xml->createElement($key, $value['val']); if (!empty($value['attr'])) { foreach ($value['attr'] as $attr_key => $attr_val) { $row->setAttribute($attr_key, $attr_val); } } $channel->appendChild($row); } $rss->appendChild($channel); foreach ($this->items as $item_key => $item) { $item_element = $xml->createElement('item'); foreach ($item as $key => $value) { $row = $xml->createElement($key, $value['val']); if (!empty($value['attr'])) { foreach ($value['attr'] as $attr_key => $attr_val) { $row->setAttribute($attr_key, $attr_val); } } $item_element->appendChild($row); } $channel->appendChild($item_element); } return $xml->saveXML(); }
<?php $dom = new domDocument('1.0'); $dom->formatOutput = true; // make output be nicely formatted $root = $dom->createElement('root'); // create new element foreach (array('foo', 'bar', 'baz') as $v) { $node = $dom->createElement($v); // create new sub-element $node->appendChild($dom->createTextNode($v)); // add value to element $root->appendChild($node); // append sub-element to root element } $dom->appendChild($root); // add root node to document $xml = $dom->saveXML(); // output XML echo nl2br(htmlspecialchars($xml));
<?php include '../Config/db.php'; header("content-type: text/xml"); $dom = new domDocument("1.0", "CP1251"); $root = $dom->createElement("Orders"); $dom->appendChild($root); $query = mysql_query(@"SELECT\n agent_orders.*,\n customers.keycode as customerKey\n FROM agent_orders\n LEFT JOIN customers ON agent_orders.customer_id = customers.id\n WHERE agent_orders.status = 0"); while ($do = mysql_fetch_array($query)) { $order = $dom->createElement("Order"); $number = $dom->createElement("Number", $do['id']); $clientID = $dom->createElement("ClientID", $do['customerKey']); $comment = $dom->createElement("Comment", $do['comment']); $products = $dom->createElement("Products"); $pquery = mysql_query("SELECT\n agent_cart.*,\n products.keycode\n FROM agent_cart\n LEFT JOIN products ON agent_cart.product_id = products.id\n WHERE order_id = '" . $do['id'] . "'"); while ($pdo = mysql_fetch_array($pquery)) { $product = $dom->createElement("Product"); $article = $dom->createElement("Key", $pdo['keycode']); $quantity = $dom->createElement("Quantity", $pdo['quantity']); $price = $dom->createElement("Price", $pdo['price']); $product->appendChild($article); $product->appendChild($quantity); $product->appendChild($price); $products->appendChild($product); } $order->appendChild($number); $order->appendChild($clientID); $order->appendChild($comment); $order->appendChild($products); $root->appendChild($order); }
<?php $document = new domDocument("1.0", "utf-8"); $domimp = new domImplementation(); $doctype = $domimp->createDocumentType('asortiment[<!ENTITY y1 "2009"> <!ENTITY y2 "2010">]'); $document->appendChild($doctype); $asortiment = $document->createElementNS("http://mysite.ru", "asort:asortiment"); $document->appendChild($asortiment); $telefon = $document->createElement("asort:telefon"); $asortiment->appendChild($telefon); $attr = $document->createAttribute("number"); $attr->nodeValue = 1; $telefon->appendChild($attr); $cdata = $document->createCDATASection("Это контент нашего интернет магазина"); $telefon->appendChild($cdata); $model_1 = $document->createElement("model"); $telefon->appendChild($model_1); $name_1 = $document->createElement("name"); $model_1->appendChild($name_1); $textN_1 = $document->createTextNode("Samsung Galaxi"); $name_1->appendChild($textN_1); $year_1 = $document->createElement("year"); $model_1->appendChild($year_1); $textY_1 = $document->createTextNode('2009'); $year_1->appendChild($textY_1); $model_2 = $document->createElement("model"); $telefon->appendChild($model_2); $name_2 = $document->createElement("name"); $model_2->appendChild($name_2); $textN_2 = $document->createTextNode("Nokia Lumia"); $name_2->appendChild($textN_2);
function add_child($root, $data) { $item = $root->createElement("item"); foreach ($data as $k => $v) { $element = $root->createElement($k); $element->appendChild($root->createTextNode($v)); $item->appendChild($element); } $root->documentElement->appendChild($item); } // Using Sax retrive the 1st entry from each rdf feed // Since we do not intend to parse the entire file SAX is // more effecient then DOM in this case. $path = dirname(__FILE__); $freshmeat = parse_xml_url("{$path}/fm-releases.rdf"); $slashdot = parse_xml_url("{$path}/slashdot.rdf"); $pear = parse_xml_url("{$path}/pear.rdf"); $data = array($freshmeat, $slashdot, $pear); // now using the given rss data, make our own XML(RDF) feed. $dom = new domDocument("1.0"); // create root element $root = $dom->createElement("channel"); $dom->appendChild($root); // append children (data from existing rss feeds); foreach ($data as $v) { add_child($dom, $v); } // generate our own feed $output = $dom->saveXML(); // make output presentable echo clean($output);
<?php include_once "config.php"; $corp = $_GET["corp"]; //$corp= $_COOKIE['corp']; $result = mysqli_query($db, "\n\tSELECT id, NumberAudit, Corps_id, Type, TableType, Capacity, Area, Conditioner, CountSeats, Sockets\n\tFROM Auditorium\n\tWHERE Corps_id='{$corp}'\n\t"); $result2 = mysqli_query($db, "\n\tSELECT Abbr, ext_id\n\tFROM Corps\n\tWHERE id='{$corp}'\n\t"); $res2 = mysqli_fetch_array($result2); $dom = new domDocument("1.0", "windows-1251"); // Создаём XML-документ версии 1.0 с кодировкой windows-1251 $Data_Root = $dom->appendChild($dom->createElement('Data_Root')); $Descript = $Data_Root->appendChild($dom->createElement('Descript')); $Descript->setAttribute("ExpSet_Code", '014'); $Descript->setAttribute("ExpSet_Name", 'Auditorium'); $Descript->appendChild($dom->createCDATASection('')); $Data = $Data_Root->appendChild($dom->createElement('Data')); $Collection = $Data->appendChild($dom->createElement('Collection')); $Collection->setAttribute("caption", 'Аудитории'); $Collection->setAttribute("name", 'Data.Auditorium'); $Collection->setAttribute("child_tags", 'Object'); while ($res = mysqli_fetch_array($result)) { $auditor_id = $res[0]; $num_audit = $res[1]; $abbr_corp = $res2[0]; $ext_id_corp = $res2[1]; $capasity_audit = $res[5]; $type_audit = $res[3]; $square_audit = $res[6]; $table_type = $res[4]; $conditioner = $res[7]; $result3 = mysqli_query($db, "\n\t\tSELECT Amount\n\t\tfrom Auditorium_Equipment\n\t\twhere Auditorium_id='{$auditor_id}' and Equipment_id=1\n\t");
/За каждую часть XML-документа отвечает определенный класс, сначала надо создать каждую часть XML-документа, а потом соединить их все вместе. ***Метод createElement("element_1", "Text Node") объекта класса domDocument - создает новый элемент XML-документа (1-наименование элемента, 2- значение элемента), так же можно создать элемент с помощью класса domElement передав конструктору название элемента и его значение (new domElement("element_2", 145)) ***Метод createElementNS("nameSpace","main:element_1", "Text Node") объекта класса domDocument - создает новый элемент XML-документа (1-namespace, 2-наименование элемента, 3- значение элемента), так же можно создать элемент с помощью класса domElement передав конструктору название элемента, его значение и namespace (new domElement("element_2", 145, "namespace")) ***Метод createAttribute("attr_1") объекта класса domDocument - создает новый атрибут элемента (1-наименование элемента),а чтобы задать его значение используем свойство nodeValue, так же можно создать атрибут с помощью класса domAttr передав конструктору название атрибута и его значение (new domAttr("element_2", 145)) ***Метод createAttributeNS("nameSpace","at:attr_1") объекта класса domDocument - создает новый атрибут элемента с указанным namespace(1-namespace, 2-наименование элемента). ***Метод createCdataSection("Section CDATA 1") объекта класса domDocument - создает секцию CDATA (1-значение для секции CDATA), так же можно создать секцию CDATA с помощью класса domCdataSection передав конструктору его значение (new domCdataSection("Section CDATA 2")) ***Метод createTextNode("Text Node 1") объекта класса domDocument - создает текстовый узел (1-значение текстового узла), так же можно создать текстовый узел с помощью класса domText передав конструктору его значение (new domText("Text Node 2")) ***Метод createComment("Comment 1") объекта класса domDocument - создает комментарий (1-значение комментария), так же можно создать комментарий с помощью класса domComment передав конструктору его значение (new domComment("Comment 2")) ***Метод appendChild($comment) - добавляет дочерний элемент в конец(1-указываем элемент который добавляем в XML-документ) ***Метод insertBefore(new domElement("el3"), $element2) - добавляет дочерний элемент перед указанным элементом (1-добавляемый элемент, 2 - элемент перед которым добавляют) ***Метод replaceChild(new domElement("el4"), $element1) - заменяет дочерний элемент на указанный (1-элемент на который заменяем, 2-элемент который заменяем) ***Метод removeChild($element1) - удаляет указанный дочерний элемент(1-элемент который удаляем) ***Метод removeAttributeNode($attr) - удаляет указанный атрибут узла(1-атрибут который хотим удалить) */ $document = new domDocument("1.0", "utf-8"); $element_1 = $document->createElement("element_1", "Text Node"); $element_2 = new domElement("element_2", 145); echo $element_1->nodeName . "<br>"; echo $element_2->nodeName . "<br>"; echo $element_1->nodeValue . "<br/>"; echo $element_2->nodeValue . "<br/>"; echo "---------------------------------------*<br/>"; $attr_1 = $document->createAttribute("attr_1"); $attr_1->nodeValue = 20; $attr_2 = new domAttr("attr_2", 64); echo $attr_1->nodeName . "<br>"; echo $attr_2->nodeName . "<br>"; echo $attr_1->nodeValue . "<br/>"; echo $attr_2->nodeValue . "<br/>"; echo "---------------------------------------*<br/>"; $cdata_1 = $document->createCdataSection("Section CDATA 1");