sax_xml.php
<?php
$xmlstr = <<<XML
<?xml version='1.0' encoding='utf-8' standalone='yes'?>
<books>
<book>
<title>PHP完全手册</title>
<price>39.8</price>
<introduction>
一本十分畅销的有关phpweb开发的经典之作,作者根据自己丰富经验而著。
</introduction>
<bookstore>
<weihai>新华书店</weihai>
<jinan>科技书店</jinan>
</bookstore>
<book-img type= "thumbs">php01.jpg</book-img>
</book>
</books>
XML;
?>
$xmlstr = <<<XML
<?xml version='1.0' encoding='utf-8' standalone='yes'?>
<books>
<book>
<title>PHP完全手册</title>
<price>39.8</price>
<introduction>
一本十分畅销的有关phpweb开发的经典之作,作者根据自己丰富经验而著。
</introduction>
<bookstore>
<weihai>新华书店</weihai>
<jinan>科技书店</jinan>
</bookstore>
<book-img type= "thumbs">php01.jpg</book-img>
</book>
</books>
XML;
?>
sax1.php:
<?php
include "sax_xml.php";
echo nl2br( "在威海哪里可以买到?\n");
$xml= new SimpleXMLElement($xmlstr);
echo $xml->book[0]->bookstore->weihai;
?>
include "sax_xml.php";
echo nl2br( "在威海哪里可以买到?\n");
$xml= new SimpleXMLElement($xmlstr);
echo $xml->book[0]->bookstore->weihai;
?>
本文转自 xcf007 51CTO博客,原文链接:http://blog.51cto.com/xcf007/148286
,如需转载请自行联系原作者