php xml

1.php
<?php
$xmlStr =file_get_contents("1.xml");
$dom = new DOMDocument('1.0');
$dom ->loadXML($xmlStr);
$xml = simplexml_import_dom($dom);
$xpath = new DOMXPath($dom);
$emps=$xpath->query("/root/members/member/name");
echo $emps->item(0)->nodeValue;
$emps->item(0)->nodeValue = "0";
echo $xml ->members[0]->member[0]->name; // aaa
$xmlBack=$dom->saveXML();
file_put_contents("1.xml",$xmlBack);

/**
echo $xml ->members[0]->member[0]->name; // aaa

echo $xml ->members[1]->member[0]->name; // 111
echo "<p>";

Ñ­»·Áгö µÚÒ»žö members µÄ name;

foreach($xml ->members[0] as $v)
{
echo $v->name."<br>";
}
*
*/
?>
1.xml
<?xml version="1.0"?>
<root>
<members>
<member>
<name>0</name>
</member>
<member>
<name>bbb</name>
</member>
<member>
<name>ccc</name>
</member>
<member>
<name>ddd</name>
</member>
</members>
<members>
<member>
<name>11</name>
</member>
<member>
<name>22</name>
</member>
<member>
<name>33</name>
</member>
<member>
<name>44</name>
</member>
</members>
</root>
posted @ 2011-06-09 21:04  wangkangluo1  阅读(246)  评论(0编辑  收藏  举报