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">
<shop>
<offers>
 <offer id="2164" available="true" >
<url>https://</url>
<price>779</price>
<currencyId>RUR</currencyId>
</offer>
 <offer id="2165" available="true" >
<url>https://2</url>
<price>780</price>
<currencyId>RUR</currencyId>
</offer>
</offers>
</shop>
</yml_catalog>

It is necessary to add static:

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

Do

$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
Solution
So
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