<?xml version="1.0" encoding="UTF-8"?> <dict num="219" id="219" name="219"> <key>天空</key> <pos></pos> <acceptation>Array;Array;</acceptation> <sent> <orig>The church tower stood against the sky like a finger pointing towards heaven.</orig> <trans>教堂的尖塔在天空的映襯下宛如指向天空的手指。</trans> </sent> <sent> <orig>A balloon floated across the sky.</orig> <trans>氣球飄過天空。</trans> </sent> <sent> <orig>A bolt of lightning lit up the sky.</orig> <trans>(一道)閃電照亮了天空。</trans> </sent> <sent> <orig>A bright moving object appeared in the sky at sunset.</orig> <trans>日落西山時,天空出現了一個移動的發亮物體。</trans> </sent> <sent> <orig>A bright rainbow arched above.</orig> <trans>一彎明亮的彩虹懸掛在天空。</trans> </sent> </dict>在PHP語言中我們可以用以下方法取得我們想要的值: <?php $xmldata = simplexml_load_file("iciba.xml"); header("Content-Type: text/html; charset=UTF-8"); print_r($xmldata); //第一部分www.111cn.net $listcount = count($xmldata->sent); for($i=0;$i<$listcount;$i++){ //第二部分 $dictlist = $xmldata->sent[$i]; echo "<br />例句:".$dictlist->orig; echo "<br />翻譯:".$dictlist->trans; } ?>“第一部分”將輸出: SimpleXMLElement Object ( [@attributes] => Array ( [num] => 219 [id] => 219 [name] => 219 ) [key] => 天空 [pos] => SimpleXMLElement Object ( ) [acceptation] => Array;Array; [sent] => Array ( [0] => SimpleXMLElement Object ( [orig] => The church tower stood against the sky like a finger pointing towards heaven. [trans] => 教堂的尖塔在天空的映襯下宛如指向天空的手指。 ) [1] => SimpleXMLElement Object ( [orig] => A balloon floated across the sky. [trans] => 氣球飄過天空。 ) [2] => SimpleXMLElement Object ( [orig] => A bolt of lightning lit up the sky. [trans] => (一道)閃電照亮了天空。 ) [3] => SimpleXMLElement Object ( [orig] => A bright moving object appeared in the sky at sunset. [trans] => 日落西山時,天空出現了一個移動的發亮物體。 ) [4] => SimpleXMLElement Object ( [orig] => A bright rainbow arched above. [trans] => 一彎明亮的彩虹懸掛在天空。 ) ) )“第二部分”將輸出: |