易截截图软件、单文件、免安装、纯绿色、仅160KB

php解析xml示例

<!-- xml 格式
<books>
<book id='1001'>
<author>andylin</author>
<title>c language</title>
<publisher id="aaa">O'Reilly</publisher>
</book>

<book id='1002'>
<author>congfeng</author>
<title>C++ Designer</title>
<publisher id='bbb'>New Publish</publisher>
</book>
</books>
-->
<?php
$dom = new DOMDocument();
if (!$dom->load('books.xml'))
{
echo "load books.xml failed!<br>";
return;
}

$books = $dom->getElementsByTagName('book');
foreach ($books as $book)
{
//get book id
$book_id = $book->getAttribute('id');

//get author
$nodeAuth = $book->getElementsByTagName('author');
$strAuth = $nodeAuth->item(0)->nodeValue;
//get publisher
$nodePub = $book->getElementsByTagName('publisher');
$strPub = $nodePub->item(0)->nodeValue;
$pub_id = $nodePub->item(0)->getAttribute('id');
//get title
$nodeTitle = $book->getElementsByTagName('title');
$strTitle = $nodeTitle->item(0)->nodeValue;

//save data
$arrInfo['book_id'] = $book_id;
$arrInfo['author'] = $strAuth;
$arrInfo['publiser'] = $strPub;
$arrInfo['title'] = $strTitle;
$arrInfo['pub_id'] = $pub_id;
//save info
$arrInfos[] = $arrInfo;
}

var_dump($arrInfos);
?>

 


相关文档:

.net 程序发布后xml文件找不到的两种解决方法

自己做项目需要用智能客户端发布,我遇到了个问题就是程序中的xml文件在发布后找不到了。经过在网上查询和自己的试验发现这两个方法都可以解决这个问题。
方法1
    右键winUI项目,发布-〉应用程序文件....->选择xml文件-〉发布状态改为“数据文件(自动)”
   
 &nb ......

用 PHP 读取和编写 XML DOM


用 PHP 读取和编写 XML DOM
使用 DOM 库、SAX 解析器和正则表达式
文档选项
打印本页
将此页作为电子邮件发送
级别: 中级
Jack Herrington (jack_d_herrington@codegeneration.net), 高级软件工程师, "Code Generation Network"
2006 年 2 月 06 日
有许多技术可用于用 PHP 读取和编写 XML。本文提供了三种 ......

PHP实例:用PHP简单实现多条件查询

在我们的网站设计过程中,经常会用到多条件查询,本文的源码是一个二手房屋查询的例子。在本例中,我们要实现能够通过地理位置,物业类型,房屋价格,房屋面积及信息发布日期等多个条件查询到客户所需的资料。
查询文件(search.php)
一、生成查询语句:
以下为引用的内容:
<?
$conn=mysql_connect("localhost", ......

php应用

最近在学习php,页面已经做好了,现在就是和虚拟机里C代码的通信,socket编程还可以,就是拿数据的处理,难,。
类的编程我不会,没有学过C++。本来打算用结构体的,可是PHP里面居然没有结构体,怎么办呢?继续努力吧
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号