本文整理汇总了PHP中domDocument::loadXML方法的典型用法代码示例。如果您正苦于以下问题:PHP domDocument::loadXML方法的具体用法?PHP domDocument::loadXML怎么用?PHP domDocument::loadXML使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类domDocument
的用法示例。
在下文中一共展示了domDocument::loadXML方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: readContent
function readContent()
{
$data = read_xml_file($this->server, $this->port, $this->url);
if (strlen($data) > 0) {
$dom = new domDocument();
$dom->loadXML(substr($data, 0, strrpos($data, '>') + 1));
$arrFeeds = array();
$count = 0;
foreach ($dom->getElementsByTagName('item') as $node) {
if (function_exists('date_parse')) {
$date_raw = date_parse($node->getElementsByTagName('pubDate')->item(0)->nodeValue);
//$date = date('H:i j.m.Y', mktime($date_raw['hour'], $date_raw['minute'], $date_raw['second'], $date_raw['month'], $date_raw['day'], $date_raw['year']));
$date = date('j.m', mktime($date_raw['hour'], $date_raw['minute'], $date_raw['second'], $date_raw['month'], $date_raw['day'], $date_raw['year']));
} else {
$date1 = explode(' ', $node->getElementsByTagName('pubDate')->item(0)->nodeValue);
$months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
$months_n = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
$time = explode(':', $date1[4]);
//$date = $time[0] . ':' . $time[1] . ' ' . intval($date1[1]) . '.' . str_replace($months, $months_n, $date1[2]) . '.' . $date1[3];
$date = intval($date1[1]) . '.' . str_replace($months, $months_n, $date1[2]);
}
$itemRSS = array('title' => mb_convert_case(!$this->decodeUTF ? utf8_decode($node->getElementsByTagName('title')->item(0)->nodeValue) : $node->getElementsByTagName('title')->item(0)->nodeValue, MB_CASE_UPPER, "UTF-8"), 'description' => substr(!$this->decodeUTF ? utf8_decode($node->getElementsByTagName('description')->item(0)->nodeValue) : $node->getElementsByTagName('description')->item(0)->nodeValue, 0, 60), 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue);
$itemRSS['date'] = $date;
array_push($arrFeeds, $itemRSS);
$count++;
if ($count == $this->nr_of_posts) {
break;
}
}
return $arrFeeds;
}
return null;
}
示例2: getCompteDisplay
function getCompteDisplay()
{
$dom = new domDocument();
$arr = array(utf8_decode('é') => "\\351", utf8_decode('è') => "\\350", utf8_decode('ç') => "\\347", utf8_decode('à') => "\\340", utf8_decode('ù') => "\\371");
$clientdata = strtr($_SESSION['client'], $arr);
$dom->loadXML($clientdata);
if (!$dom) {
echo "Error while parsing the document\n";
exit;
}
$s = simplexml_import_dom($dom);
return strtoupper($s->nom) . ' ' . strtoupper($s->prenom) . ',' . $s->clientid . ',' . $s->type;
}
示例3: main
function main()
{
$dom = new domDocument();
$string = <<<END
<a>
<b>c</b>
</a>
END;
$dom->loadXML($string);
$s = simplexml_import_dom($dom);
$dom = null;
var_dump((string) $s->b);
}
示例4: getTextBetweenTags
/**
*
* from http://www.phpro.org/examples/Get-Text-Between-Tags.html
*
* @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
* @return array
*
*/
function getTextBetweenTags($tag, $html, $strict = 0)
{
$dom = new domDocument();
if ($strict == 1) {
$dom->loadXML($html);
} else {
$dom->loadHTML($html);
}
$dom->preserveWhiteSpace = false;
$content = $dom->getElementsByTagname($tag);
$out = array();
foreach ($content as $item) {
$out[] = $item->nodeValue;
}
return $out;
}
示例5: getCompteType
function getCompteType()
{
$dom = new domDocument();
$arr = array(utf8_decode('é') => "\\351", utf8_decode('è') => "\\350", utf8_decode('ç') => "\\347", utf8_decode('à') => "\\340", utf8_decode('ù') => "\\371");
$clientdata = strtr($_SESSION['client'], $arr);
$dom->loadXML($clientdata);
if (!$dom) {
echo "Error while parsing the document\n";
exit;
}
$s = simplexml_import_dom($dom);
if ($s->type == "client") {
return "C";
} else {
return "M";
}
}
示例6: frameResponse
public function frameResponse(\FrameResponseObject $frameResponseObject)
{
$mplme = \steam_factory::get_object($GLOBALS["STEAM"]->get_id(), $this->id);
$frameResponseObject->setTitle("Mplme");
if (isset($_REQUEST["xmlData"])) {
$xmlDoc = \steam_factory::get_object_by_name($GLOBALS["STEAM"]->get_id(), $mplme->get_path() . "/data.xml");
if ($xmlDoc === 0 || !$xmlDoc instanceof \steam_document) {
$xml = simplexml_load_string("<datasets></datasets>");
$xmlDoc = \steam_factory::create_document($GLOBALS["STEAM"]->get_id(), "data.xml", $xml->asXML(), "text/xml");
$xmlDoc->move($mplme);
} else {
$xmlRaw = $xmlDoc->get_content();
$xml = simplexml_load_string($xmlRaw);
}
$xmlRequest = simplexml_load_string($_REQUEST["xmlData"]);
$xmlRequestDom = new \domDocument();
$xmlRequestDom->loadXML($xmlRequest->asXML());
$xmlDom = new \domDocument();
$xmlDom->loadXML($xml->asXML());
$xmlDom->documentElement->appendChild($xmlDom->importNode($xmlRequestDom->documentElement, true));
if ($_FILES && is_array($_FILES)) {
foreach ($_FILES as $file) {
$content = file_get_contents($file["tmp_name"]);
$doc = \steam_factory::create_document($GLOBALS["STEAM"]->get_id(), $file["name"], $content, $file["type"]);
$doc->move($mplme);
}
}
$xmlDoc->set_content($xmlDom->saveXML());
//echo "<pre>" . htmlentities($xmlDom->saveXML()) . "</pre>";
echo "ok";
} else {
echo "nix";
}
die;
//echo "done";
//$frameResponseObject->addWidget(new \Widgets\Blank());
//return $frameResponseObject;
}
示例7: getTextBetweenTags
/**
*
* @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
*
* @return array
*
*/
function getTextBetweenTags($tag, $html, $strict = 0)
{
/*** a new dom object ***/
$dom = new domDocument();
/*** load the html into the object ***/
if ($strict == 1) {
$dom->loadXML($html);
} else {
$dom->loadHTML($html);
}
/*** discard white space ***/
$dom->preserveWhiteSpace = false;
/*** the tag by its tag name ***/
$content = $dom->getElementsByTagname($tag);
/*** the array to return ***/
$out = array();
foreach ($content as $item) {
/*** add node value to the out array ***/
$out[] = $item->nodeValue;
}
/*** return the results ***/
return $out;
}
示例8: getfoafdom
public function getfoafdom(&$foafurl)
{
$s = http::get($foafurl);
if (!$s) {
return false;
}
if (!$this->isfoaf($s)) {
$foafurl = $this->discoverfoafurl($s);
if (!$foafurl) {
return false;
}
$s = http::get($foafurl);
if (!$s) {
return false;
}
if (!$this->isfoaf($s)) {
return false;
}
}
$dom = new domDocument();
$dom->loadXML($s);
return $dom;
}
示例9: getTextBetweenTags
/**
* Returns the text between 2 tags
*
* @return array
* @param string $tag The tag.
* @param string $html The HTML to search in.
* @param bool[optional] $strict Use strictmode?
*/
private function getTextBetweenTags($tag, $html, $strict = false)
{
// new dom document
$dom = new domDocument();
// load HTML
$strict == true ? $dom->loadXML($html) : $dom->loadHTML($html);
// discard whitespace
$dom->preserveWhiteSpace = false;
// the array with results
$results = array();
// fetch the tag by name
$content = $dom->getElementsByTagname($tag);
// loop the content
foreach ($content as $item) {
// add node value to results
$results[] = $item->nodeValue;
}
// return the results
return $results;
}
示例10: domDocument
<article id="2">
<title>Something Else Happened</title>
<author>Different Person</author>
</article>
</articles>';
$xsl = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml" encoding="iso-8859-1" />
<xsl:template match="/">
<xsl:apply-templates select="//article"/>
</xsl:template>
<xsl:template match="article">
Title: <xsl:value-of select="title"/><br />
Author: <xsl:value-of select="author"/><br />
<hr />
</xsl:template>
</xsl:stylesheet>';
/* load XSLT Stylesheet */
$xslDom = new domDocument();
$xslDom->loadXML($xsl);
/* load XML data */
$xmlDom = new domDocument();
$xmlDom->loadXML($xml);
$xsl = new XsltProcessor();
// instantiate XSLT processor
$xsl->importStylesheet($xslDom);
// load stylesheet
echo $xsl->transformToXML($xmlDom);
// perform the transformation & return HTML
示例11: importBooksXML
static function importBooksXML($files_name_pars, $catid)
{
$files_name_pars = file($files_name_pars);
$files_name_pars = implode('', $files_name_pars);
//echo $files_name_pars;
global $database;
$retVal = array();
$new_categories = array();
$k = 0;
$dom = new domDocument('1.0', 'utf-8');
$dom->loadXML($files_name_pars);
$version = $dom->getElementsByTagName('version');
if ($version->item(0) != NULL) {
$numversion = explode(' ', $version->item(0)->nodeValue);
if (intval($numversion[0]) >= 2) {
$categories_xml = $dom->getElementsByTagName('category');
if ($categories_xml->item(0) != NULL) {
//�µÑ��»�¸ �² XML �µÑ�Ñ‚ÑŒ Ñ��¿�¸Ñ��¾�º �º�°Ñ‚�µÑ€�¾�³�¸�¹ �´�»Ñ� �¸�¼�¿�¾Ñ€Ñ‚�°
mosBooklibraryImportExport::remove_info();
//ч�¸Ñ�Ñ‚�¸�¼ �±�°�·Ñƒ �´�°�½�½Ñ‹Ñ…
if ($catid === null) {
//�µÑ��»�¸ �º�°Ñ‚�µ�³�¾Ñ€�¸Ñ� �´�»Ñ� �¸�¼�¿�¾Ñ€Ñ‚�° �½�µ �²Ñ‹�±Ñ€�°�½�°
for ($i = 0; $i < $categories_xml->length; $i++) {
$category = $categories_xml->item($i);
$new_category = new stdClass();
$new_category->old_id = mosBooklibraryImportExport::getXMLItemValue($category, 'id');
$new_category->old_parent_id = mosBooklibraryImportExport::getXMLItemValue($category, 'parent_id');
$new_category->name = mosBooklibraryImportExport::getXMLItemValue($category, 'name');
$new_category->title = mosBooklibraryImportExport::getXMLItemValue($category, 'title');
$new_category->alias = mosBooklibraryImportExport::getXMLItemValue($category, 'alias');
$new_category->published = mosBooklibraryImportExport::getXMLItemValue($category, 'published');
$new_category->ordering = mosBooklibraryImportExport::getXMLItemValue($category, 'ordering');
$new_category->access = mosBooklibraryImportExport::getXMLItemValue($category, 'access');
$new_category->description = mosBooklibraryImportExport::getXMLItemValue($category, 'description');
$new_category->params = mosBooklibraryImportExport::getXMLItemValue($category, 'params');
$new_category->params2 = mosBooklibraryImportExport::getXMLItemValue($category, 'params2');
$new_category = mosBooklibraryImportExport::findCategory($new_categories, $new_category);
}
}
mosBooklibraryImportExport::refreshCategoryParentId($new_categories);
}
//end if exist categories
//exit;
$books_xml = $dom->getElementsByTagName('book');
foreach ($books_xml as $i => $book_xml) {
//echo mosBooklibraryImportExport::getXMLItemValue($book_xml,'bookid');
$book = new mosBooklibrary($database);
//get BookID
$book->bookid = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'bookid');
//get ISBN
$book->isbn = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'isbn');
//get Title(book)
$book->title = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'title');
//get Authors
$book->authors = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'authors');
//get Manufacturer
$book->manufacturer = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'manufacturer');
//get releasedate
$book->release_Date = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'releaseDate');
//get language
$book->language = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'language');
$book->langshow = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'langshow');
if ($book->langshow == "") {
$book->langshow = "*";
}
//get hits
$book->hits = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'hits');
$book->user_name = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'user_name');
//get featured_clicks
$book->featured_clicks = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'featured_clicks');
//get featured_shows
$book->featured_shows = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'featured_shows');
//get rating
$book->rating = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'rating');
//get price
$book->price = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'price');
//get priceunit
$book->priceunit = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'priceunit');
//get URL
$book->URL = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'url');
//get imageURL
$book->imageURL = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'imageURL');
//get edition
$book->edition = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'edition');
//get ebookURL
$book->ebookURL = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'ebookURL');
//get informationFrom
$book->informationFrom = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'informationFrom');
//get date
$book->date = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'date');
//get published
$book->published = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'published');
//get comment
$book->comment = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'comment');
//get numberOfPages
$book->numberOfPages = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'numberOfPages');
$book->comment = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'comment');
//get email owner book
$book->owneremail = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'owneremail');
//get email owner book
//.........这里部分代码省略.........
示例12: get_items_datas
protected function get_items_datas($items)
{
$datas = array();
foreach ($items as $item) {
$informations = array();
$notice = new notice($item);
//s'agit-il d'une notice de flux RSS ?
$eformat = array();
$eformat = explode(' ', $notice->eformat);
if ($eformat[0] == 'RSS' && $notice->lien != '') {
@ini_set("zend.ze1_compatibility_mode", "0");
$loaded = false;
$aCurl = new Curl();
$aCurl->timeout = 2;
$content = $aCurl->get($notice->lien);
$flux = $content->body;
if ($flux && $content->headers['Status-Code'] == 200) {
$rss = new domDocument();
$old_errors_value = false;
if (libxml_use_internal_errors(true)) {
$old_errors_value = true;
}
$loaded = $rss->loadXML($flux);
}
if (!count(libxml_get_errors())) {
if ($loaded) {
//les infos sur le flux...
//Flux RSS
if ($rss->getElementsByTagName("channel")->length > 0) {
$channel = $rss->getElementsByTagName("channel")->item(0);
$elements = array('url');
$informations = $this->get_informations($channel, $elements, 1);
//on va lire les infos des items...
$informations['items'] = array();
$rss_items = $rss->getElementsByTagName("item");
$elements = array('title', 'description', 'link', 'pubDate', 'category');
for ($i = 0; $i < $rss_items->length; $i++) {
if ($this->parameters['nb_max_elements'] == 0 || $i < $this->parameters['nb_max_elements']) {
$informations['items'][] = $this->get_informations($rss_items->item($i), $elements, false);
}
}
//Flux ATOM
} elseif ($rss->getElementsByTagName("feed")->length > 0) {
$feed = $rss->getElementsByTagName("feed")->item(0);
$atom_elements = array('url');
$informations = $this->get_atom_informations($feed, $atom_elements, 1);
//on va lire les infos des entries...
$informations['items'] = array();
$entries = $rss->getElementsByTagName("entry");
$atom_elements = array('title', 'link', 'published', 'content');
for ($i = 0; $i < $entries->length; $i++) {
if ($this->parameters['nb_max_elements'] == 0 || $i < $this->parameters['nb_max_elements']) {
$informations['items'][] = $this->get_atom_informations($entries->item($i), $atom_elements, false);
}
}
}
foreach ($informations['items'] as $rss_item) {
$data = array();
$data["num_notice"] = "0";
$data["type"] = "rss";
$data["title"] = $rss_item["title"];
$data["summary"] = $rss_item["description"];
$data["content"] = $rss_item["description"];
$data["url"] = $rss_item["link"];
$data["publication_date"] = date('Y-m-d h:i:s', strtotime($rss_item["pubDate"]));
$data["logo_url"] = $informations["url"];
$data["descriptors"] = "";
if (is_array($rss_item["category"])) {
$data["tags"] = array_map("strip_tags", $rss_item["category"]);
} else {
$data["tags"] = strip_tags($rss_item["category"]);
}
$datas[] = $data;
}
}
} else {
libxml_clear_errors();
}
libxml_use_internal_errors($old_errors_value);
@ini_set("zend.ze1_compatibility_mode", "1");
return $datas;
}
}
return false;
}
示例13: Simpla
require_once '../../api/Simpla.php';
$simpla = new Simpla();
//$category_id = $simpla->request->get('category_id', 'integer');
//$product_id = $simpla->request->get('product_id', 'integer');
//курс с сайта ЦБ РФ
$corrency_output = array();
$date = date("d/m/Y");
// Сегодняшняя дата в необходимом формате
$link = "http://www.cbr.ru/scripts/XML_daily.asp?date_req={$date}";
// Ссылка на XML-файл с курсами валют
$content = file_get_contents($link);
// Скачиваем содержимое страницы
$dom = new domDocument("1.0", "cp1251");
// Создаём DOM
$dom->loadXML($content);
// Загружаем в DOM XML-документ
$root = $dom->documentElement;
// Берём корневой элемент
$childs = $root->childNodes;
// Получаем список дочерних элементов
$data = array();
// Набор данных
for ($i = 0; $i < $childs->length; $i++) {
$childs_new = $childs->item($i)->childNodes;
// Берём дочерние узлы
for ($j = 0; $j < $childs_new->length; $j++) {
/* Ищем интересующие нас валюты */
$el = $childs_new->item($j);
$code = $el->nodeValue;
if ($code == "USD" || $code == "EUR") {
示例14: array
function get_corrency()
{
//тест курс доллара по цб
$corrency_output = array();
$date = date("d/m/Y");
// Сегодняшняя дата в необходимом формате
$link = "http://www.cbr.ru/scripts/XML_daily.asp?date_req={$date}";
// Ссылка на XML-файл с курсами валют
$content = file_get_contents($link);
// Скачиваем содержимое страницы
$dom = new domDocument("1.0", "cp1251");
// Создаём DOM
$dom->loadXML($content);
// Загружаем в DOM XML-документ
$root = $dom->documentElement;
// Берём корневой элемент
$childs = $root->childNodes;
// Получаем список дочерних элементов
$data = array();
// Набор данных
for ($i = 0; $i < $childs->length; $i++) {
$childs_new = $childs->item($i)->childNodes;
// Берём дочерние узлы
for ($j = 0; $j < $childs_new->length; $j++) {
/* Ищем интересующие нас валюты */
$el = $childs_new->item($j);
$code = $el->nodeValue;
if ($code == "USD" || $code == "EUR") {
$data[] = $childs_new;
}
// Добавляем необходимые валюты в массив
}
}
/* Перебор массива с данными о валютах */
for ($i = 0; $i < count($data); $i++) {
$list = $data[$i];
for ($j = 0; $j < $list->length; $j++) {
$el = $list->item($j);
/* Выводим курсы валют */
if ($el->nodeName == "Name") {
$corrency_output[$i]->key = $el->nodeValue . " - ";
} elseif ($el->nodeName == "Value") {
$corrency_output[$i]->val = $el->nodeValue . "р.";
}
}
}
$this->design->assign("corrency_cbrf", $corrency_output);
//get products
//$this->design->smarty->registerPlugin("function", "get_products", array($this, 'get_products_plugin'));
//тест
}
示例15: trim
<?php
$xmlstring = '<?xml version="1.0" ?>
<!DOCTYPE books [
<!ATTLIST book id ID #IMPLIED>
]>
<books>
<book id="1">
<title>Book 1</title>
</book>
<book id="2">
<title>Book 2</title>
</book>
</books>';
$dom = new domDocument();
/* load XML from string */
$dom->loadXML($xmlstring);
/* get the node identified by id #2 */
$node = $dom->getElementById("2");
print trim($node->nodeValue);