一、php程序部分
1、方法一 simplexml读取xml
//
$xml_array=simplexml_load_file('person.xml'); //将XML中的数据,读取到数组对象中
foreach($xml_array as $tmp){
echo $tmp->name.'-'.$tmp->sex.'-'.$tmp->old.'
';
}
?>
2、方法二 //DOMDocument读取xml
$doc = new DOMDocument();
$doc->load('person.xml'); //读取xml文件
$humans = $doc->getElementsByTagName( 'humans' ); //取得humans标签的对象数组
foreach( $humans as $human )
{
$names = $human->getElementsByTagName( 'name' ); //取得name的标签的对象数组
$name = $names->item(0)->nodeValue; //取得node中的值,如
$sexs = $human->getElementsByTagName( 'sex' );
$sex = $sexs->item(0)->nodeValue;
$olds = $human->getElementsByTagName( 'old' );
$old = $olds->item(0)->nodeValue;
echo "$name - $sex - $old ".'
';
}
?>
二、xml部分
hongye
man
12age
han
man
14age
hy
woman
17age