【适合所有网站的rss和xml聚合功能asp代码】教程文章相关的互联网学习教程文章

php读取xml实例代码

php文件 代码如下:<?php class xpathExtension{ public static function getNodes($domDoc, $xpathString) { $xp = new DOMXPath($domDoc); $xp->registerNamespace(x, http://www.w3.org/1999/xhtml); $xp->registerNamespace(xhtml, http://www.w3.org/1999/xhtml); $xp->registerNamespace(i18n, http://apache.org/cocoon/i18n/2.1); $ret = array(); $nodes = $xp->query($xpathString); foreach ($nodes as $node) { array_...

用PHP实现读取和编写XML DOM代码

代码如下:// 用 DOM 读取 XML $doc = new DOMDocument(); $doc->load(‘test.xml); $books = $doc->getElementsByTagName(“book”); foreach( $books as $book ){ $authors = $book->getElementsByTagName(“author”); $author = $authors->item(0)->nodeValue; // nodeValue属 性可根据节点的类型来设置或返回某个节点的值。 $publishers = $book->getElementsByTagName(“publisher”); $publisher = $publishers->item(0)->no...

PHP5中使用DOM控制XML实现代码

下面的例子简单的演示了DOM对XML的操作,详细解释请看代码中的注释 代码如下:<? /************************************************ ** use XML in PHP5 ** reference site: ** http://cn.php.com/manual/zh/ref.dom.php ** the follow codes need PHP5 support *************************************************/ //首先要创建一个DOMDocument对象 $dom = new DomDocument(); //然后载入XML文件 $dom -> load("test.xml"); //...

PHP XML数据解析代码

代码如下://xml string $xml_string="<?xml version=1.0?> <users> <user id=398> <name>Foo</name> <email>foo@bar.com</name> </user> <user id=867> <name>Foobar</name> <email>foobar@foo.com</name> </user> </users>"; //load the xml string using simplexml $xml = simplexml_load_string($xml_string); //loop through the each node of user foreach ($xml->user as $user) { //access attribute echo $user[id], ; //...

PHP操作xml代码

代码如下:/*获取图片新闻列表*/ function getPicNews($number=5){ require_once 'include/content_class.php'; $Content=new Content(); $sql='select contentid as id,title,pic,typeid from `cms_content` where pic<>"" order by input_time desc'; $rows=$Content->getRowsBySQL($sql,$number); $dom=new DOMDocument('1.0','GBK'); $root=$dom->createElement('slider'); $dom->appendChild($root); foreach($rows as $val){ ...

生成ubuntu自动切换壁纸xml文件的php代码

代码如下:<?php /* * 生成ubuntu自动切换壁纸xml文件 */ //图片目录 $dir = /home/yuxing/background; $hd = opendir($dir) or die(can not open dir); $files = array(); while($file = readdir($hd)) { $tem = "$dir/$file"; if (is_file($tem) && in_array(strtolower(substr(strrchr($file,.), 1)), array(jpg, gif))) $files[] = $tem; } closedir($hd); unset($file); $xw = new xmlWriter(); $xw->openMemory(); $xw->setIn...

php中DOMDocument简单用法示例代码(XML创建、添加、删除、修改)

共分四个文件,分别是创建、增加、删除、修改四个功能,变量都是写死的,改一改用$_POST方式接收就可以用了 //index.php 创建功能 代码如下:<?php $xmlpatch = index.xml; $_id = 1; $_title = title1; $_content = content1; $_author = author1; $_sendtime = time1; $_htmlpatch = 1.html; jb51.net$doc = new DOMDocument(1.0, utf-8); $doc -> formatOutput = true; jb51.net$root = $doc -> createElement(root);//新建节点...

PHP读取XML值的代码(推荐)

用Php读取XML最简单的情况: XML文件(cy.xml)如下: 代码如下:<?xml version=”1.0″ encoding=”gb2312″?> <xml> <list>1</list> <list>2</list> <list>3</list> </xml> Php文件(cy.php)如下: 代码如下:<?php $xml = new DOMDocument(); $xml->load(cy.xml); foreach($xml->getElementsByTagName(list) as $list) { $value = $list->firstChild->nodeValue; echo $value.”<br />”; } ?> cy.php的运行结果: 1 2 3 ===========...

php simplexmlElement操作xml的命名空间实现代码

看了这个问题,第一个反应就是namespace的关系,但我从来没有使用simplexml操作过namespace,于是就翻开手册查了一下资料,问题并没有解决,最终是通过google解决了该问题。 提问题的朋友贴出了数据源,来自于:http://code.google.com/intl/zh-CN/apis/contacts/docs/3.0/developers_guide_protocol.html#retrieving_without_query,数据结构大致如下: 代码如下:<feed xmlns=http://www.w3.org/2005/Atom xmlns:openSearch=http...

用PHP读取和编写XML DOM的实现代码【图】

用 PHP 读取和编写可扩展标记语言(XML)看起来可能有点恐怖。实际上,XML 和它的所有相关技术可能是恐怖的,但是用 PHP 读取和编写 XML 不一定是项恐怖的任务。首先,需要学习一点关于 XML 的知识 —— 它是什么,用它做什么。然后,需要学习如何用 PHP 读取和编写 XML,而有许多种方式可以做这件事。 本文提供了 XML 的简短入门,然后解释如何用 PHP 读取和编写 XML。 什么是 XML? XML 是一种数据存储格式。它没有定义保存什么数...

php XPath对XML文件查找及修改实现代码

代码如下:<?php /* <?xml version="1.0" encoding="utf-8"?> <article> <item> <title name="t1">11</title> <content>content1</content> <pubdate>2009-10-11</pubdate> </item> <item> <title name="t2">title2</title> <content>content2</content> <pubdate>2009-11-11</pubdate> </item> </article> */ if(!function_exists(l)) { function l() { echo <br/>***********************************<br />; } } if(file_exists(...

php模拟asp中的XmlHttpRequest实现http请求的代码

类名 :HttpRequest($url="",$method="GET",$useSocket=0) //$url为请求的地址;默认请求方法为GET;$useSocket默认为0,使用fsockopen方法,如果设置为1则使用socket_create方法 方法: open($ip="",$port=-1) //打开同服务器的连接,默认不用设置这两个参数(一个同事在linux用的时候,请求的不是hostname解析的IP,因此加了这两个参数,以连接真实的服务器IP) setTimeout($timeout=0) //设置获取数据的超时时间,必须在send方法...

PHP用SAX解析XML的实现代码与问题分析

代码如下:<?php $g_books = array(); $g_elem = null; function startElement( $parser, $name, $attrs ) { global $g_books, $g_elem; if ( $name == BOOK ) $g_books []= array(); $g_elem = $name; } function endElement( $parser, $name ) { global $g_elem; $g_elem = null; } function textData( $parser, $text ) { global $g_books, $g_elem; if ( $g_elem == AUTHOR || $g_elem == PUBLISHER || $g_elem == TITLE ) { $g...

php XMLWriter类的简单示例代码(RSS输出)

代码如下:include mysql.php; $mysql= mysql::getObject(); $mysql->query("SELECT * FROM post"); $xml = new XMLWriter(); $xml->openUri(hello.xml); // or php://output $xml->setIndentString( ); $xml->setIndent(true); // start $xml->startDocument(1.0, UTF-8); // <rss version="2.0"> $xml->startElement(rss); $xml->writeAttribute(version,2.0); // <channel> $xml->startElement(channel); // title $xml->startEl...

php中使用DOM类读取XML文件的实现代码【图】

主要功能:php中使用DOM类读取XML文件 设计知识点: 1、XML节点循环读取 2、用iconv()函数实现编码转换,防止中文乱码 holiday.xml文件如下 代码如下:<?xml version="1.0" encoding="UTF-8"?> <daysOff-overTime> <year> <yearName>2012</yearName> <holiday> <holidayName>元旦</holidayName> <daysOff> <from>2012-1-1</from> <to>2012-1-3</to> </daysOff> <overTime> <day>2011-12-31</day> </overTime> </holiday> <holiday>...