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> <?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>'; $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 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 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
Warning: DOMDocument::loadXML(): XML declaration allowed only at the start of the document in Entity, line: 13 in /in/SMOft on line 29 Warning: DOMDocument::loadXML(): Extra content at the end of the document in Entity, line: 14 in /in/SMOft on line 29 <?xml version="1.0"?>

preferences:
58.82 ms | 408 KiB | 5 Q