06


$file="………………/test.xml";
$xml= new DomDocument("1.0");
$xml->load($file);//得到xml文档
$node=$xml->firstChild;//第一个结点
if($node->hasChildNodes())//是否有子结点 返回true或false
{
 $items=$node->childNodes;//取子结点,取出来是一个nodelist对象
 foreach ($node->childNodes as $item) { //foreach循环这些子结点
  echo $item->getAttribute("id");//取某一个属性
 }
 
}
//其他一些方法
$node->childNodes->item(0)//第一个子结点
$attributes=$node->attributes;//取得所有属性
foreach($attributes as $attribute)
{
 $tr->setAttribute($attribute->nodeName,$attribute->nodeValue);
        //属性的名字和值
}

written by 城市过客甲


Leave a Reply

i3Theme sponsored by Top 10 Web Hosting and Hosting in Colombia