1

I want to add excel file data into an existing XML file and a particular tag.

I want to add excel data of upc code into the upc tag of the XML file using PHP.

My excel file format is:

enter image description here

I want the following XML format data.

enter image description here

1
  • 2
    What have you tried, researched ? We can help you on a precise point, but you need to show some effort trying to solve this problem by yourself first. Commented Aug 30, 2017 at 20:57

1 Answer 1

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");
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.