3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = ' <GetCategories> <GetProduct> <Data> <Id>87772873</Id> <Name>Foods and Beverages</Name> <Top> <CategoryId>028392323</CategoryId> <CategoryName>Categories</CategoryName> </Top> </Data> </GetProduct> </GetCategories> '; $dom = new DOMDocument; $dom->loadXML($xml); $dom->preserveWhiteSpace = FALSE; $Xpath = new DOMXpath($dom); foreach ($Xpath->evaluate('/GetCategories/GetProduct/Data/Top[1]') as $data) { $type = $data->appendChild($dom->createElement('TypeId')); $type->appendChild($dom->createTextNode('HDU5K3KDI23F')); } $xmldata = $dom->saveXML(); echo $xmldata;
Output for 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.29, 8.2.0 - 8.2.23, 8.3.0 - 8.3.11
<?xml version="1.0"?> <GetCategories> <GetProduct> <Data> <Id>87772873</Id> <Name>Foods and Beverages</Name> <Top> <CategoryId>028392323</CategoryId> <CategoryName>Categories</CategoryName> <TypeId>HDU5K3KDI23F</TypeId></Top> </Data> </GetProduct> </GetCategories>

preferences:
77.18 ms | 408 KiB | 5 Q