Possible Duplicate:
How to modify xml file using PHP
I have an xml that looks like this:
<host host-name="www.1.com">
<root-directory>c:/public_html</root-directory>
</host>
<host host-name="www.2.com">
<root-directory>c:/public_html</root-directory>
</host>
I need do modify the xml using php like this
If the value of host-name = www.2.com
change the value of root-directory in c:/public_html/blahblah
So the final result would be:
<host host-name="www.1.com">
<root-directory>c:/public_html</root-directory>
</host>
<host host-name="www.2.com">
<root-directory>c:/public_html/blahblah</root-directory>
</host>
I really need some help. Thanks!
Update:
oh, i forgot to mention that i'm not a programmer, anyway here is what i've tried
$xmlDomain= "www.2.com";
$nomefile='myfile.xml';
$xmlDoc = new DomDocument();
$xmlDoc->load($nomefile);
$Xroot = $xmlDoc->documentElement;
$products = $Xroot->getElementsByTagName("host");
$length = $products->length;
for ($i=$length-1;$i>=0;$i--)
{
$p = $products->item($i);
$pid = $p->getAttribute("host-name");
if ($pid == $xmlDomain)
{
$parent = $xmlDoc->getElementsByTagName("root-directory");
$parent->nodeValue = 'c:/public_html/blahblah';
}
}
$strxml = $xmlDoc->saveXML();
$handle = fopen($nomefile, "w");
fwrite($handle, $strxml);
fclose($handle);