How to insert a tag in XML (simplexml)?

You need to insert a new tag with a static value in the XML:

<?xml version="1.0" encoding="windows-1251"?>
<!DOCTYPE yml_catalog SYSTEM "shops.dtd">
<yml_catalog date="2020-02-17 16:45">
 <offer id="2164" available="true" >
 <offer id="2165" available="true" >

It is necessary to add static:

<option cost="300" days="4" order-before="18"/>


$xml = simplexml_load_file('https://URI');
foreach ($xml->shop->offers->offer as $offer) {
 $name = $offer->name;
 $details = $offer->addChild('delivery-options');

The tag is added as: <delivery-options/>

I do not understand why it is not a paired tag, and how to add <option cost="300" days="4" order-before="18"/>

Is it possible to insert a simple string? Or something else?
April 7th 20 at 15:32
1 answer
April 7th 20 at 15:34
foreach ($xml->shop->offers->offer as $offer) {
 $name = $offer->name;
 $details = $offer->addChild('delivery-options',' ');
 $details_option = $details->addChild('option');
 $details_option->addAttribute('cost', '300');
 $details_option->addAttribute('days', '4');

echo $xml->asXML();

Find more questions by tags PHPXML