答案 0 :(得分:2)
$xml = simplexml_load_file("yourxmlfilename.xml");
$prod = $xml->Products;
print_r($prod->Product->count());
for($i=1; $i<=$prod->Product->count();$i++){
$str = (string) $prod->Product[$i]->ExternalId;
if($str == 'mobilesn1'){
$c = $prod->Product[$i]->UPCs;
print_r($prod->Product[$i]->UPCs->UPC);
if((string)$prod->Product[$i]->UPCs->UPC !="895623" ){
//unset($prod->Product[$i]->UPCs->UPC);
$c->addChild('UPC', '895623');
$xml->asXML("yourxmlfilename.xml");
}
}
}