易截截图软件、单文件、免安装、纯绿色、仅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);
?>

 


相关文档:

C#序列化xml的完整例子

C#序列化xml
关键步骤:
XmlSerializer xSerializer = new XmlSerializer(typeof(MyObj));
StringWriter sWriter = new StringWriter(CultureInfo.InvariantCulture);
XmlTextWriter xTextWriter = new XmlTextWriter(sWriter);
......

使用 PHP 处理 XML 配置文件


使用 PHP 处理 XML 配置文件
使用 XML 配置文件轻易地配置 PHP 应用程序和对象
级别: 中级
Vikram Vaswani, 创始人, Melonfire
2007 年 11 月 29 日
XML 为应用程序配置文件提供了一种便捷、易用的表达语言。但有时候将这些信息提取到 PHP 脚本中将会面对一个不小的挑战。这正是 XJConf for PHP 包出现的原因:它提 ......

解读PHP DOMDocument在解析XML文件中的作用

解读PHP DOMDocument在解析XML文件中的作用
http://developer.51cto.com  2009-12-02 10:39  佚名  柳城博客  我要评论(0)
PHP DOMDocument的功能非常强大,我们在这篇文章中将介绍如何正确的运用PHP DOMDocument来进行XML文件的解析。希望对又需要的朋友有所帮助。
在使用PHP对XML文件进行解析的时 ......

php获取xml属性值

<!-- xml格式
<foo xmlns="test">
<bar attr='a'></bar>
<bar attr='b'></bar>
<bar attr='c'></bar>
</foo>
-->
<?php
$dom = new DOMDocument();
if (!$dom->load('attr.xml'))
{
echo "load books.xml failed!<br>";
re ......

PHP结合OpenVC实现人脸识别

最近发现很多网站都有一些圈人头像的功能,后来在网上GG了一下,发现是用OpenCV实现的,我也在内部服务器做了一下测试,如果可以实现,步骤如下:
一 安装
1、安装opencv
官方网站:http://www.opencv.org.cn (中文版)
具体安装方法可以参考官方网站:
http://www.opencv.org.cn/index.php/%E6%BA%90%E7%A0%81%E7% ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号