<table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_15932"> <span style="font-family:Arial;line-height:24px;border-collapse:collapse;color:#333333;font-size:14px;">XML(Extensible Markup Language)即可扩展标记<span style="outline-style:none;outline-width:initial;outline-color:initial;cursor:pointer;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:#fa891b;">语言</span>,它与HTML一样,都是SGML(Standard Generalized Markup Language,标准通用标记语言)。</span> <div class="blockcode"> <div id="code_d2o"><ol> <li>xml源文件</li> <li> <li><?xml version="1.0 encoding="UTF-8"?></li> <li> <humans></li> <li> <zhangying></li> <li> <name>张映</name></li> <li> <sex>男</sex></li> <li> <old>28</old></li> <li> </zhangying></li> <li> <tank></li> <li> <name>tank</name></li> <li> <sex>男</sex></li> <li> <old>28</old></li> <li> </tank></li> <li> </humans></li> <li> <li> <li> <li> <?php<li> $doc = new DOMDocument();<li> $doc->load('person.xml'); //读取xml文件</li> <li> <li> $humans = $doc->getElementsByTagName( "humans" ); //取得humans标签的对象数组</li> <li> <li> foreach( $humans as $human )</li> <li> {</li> <li> $names = $human->getElementsByTagName( "name" ); //取得name的标签的对象数组</li> <li> $name = $names->item(0)->nodeValue; //取得node中的值,如<name> </name></li> <li> <li> $sexs = $human->getElementsByTagName( "sex" );</li> <li> $sex = $sexs->item(0)->nodeValue;</li> <li> <li> $olds = $human->getElementsByTagName( "old" );</li> <li> $old = $olds->item(0)->nodeValue;</li> <li> <li> echo "$name - $sex - $oldn";</li> <li> <li> }</li> <li> ?></li> </ol></div> <em onclick="copycode($('code_d2o'));">复制代码</em> </div> </td></tr></table> <div id="comment_15932" class="cm"> </div> <div id="post_rate_div_15932"></div> <br><br>