xml-to-array
xml-to-array copied to clipboard
XmlToArray::convertDomElement() must be an instance of DOMElement, instance of DOMComment given
Hi, i am trying to convert the next xml: http://gd2.mlb.com/components/game/mlb/year_2019/month_05/day_02/gid_2019_05_02_slnmlb_wasmlb_1/atv_preview.xml
But it doesnt work i get the next error:
Argument 1 passed to Vyuldashev\XmlToArray\XmlToArray::convertDomElement() must be an instance of DOMElement, instance of DOMComment given, called in vendor\vyuldashev\xml-to-array\src\XmlToArray.php on line 105 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Argument 1 passed to Vyuldashev\\XmlToArray\\XmlToArray::convertDomElement() must be an instance of DOMElement, instance of DOMComment given, called in vendor\\vyuldashev\\xml-to-array\\src\\XmlToArray.php on line 105 at vendor\\vyuldashev\\xml-to-array\\src\\XmlToArray.php:58)
If i remove the comments on there i get the next error
Illegal string offset 'leftLabel' {"exception":"[object] (ErrorException(code: 0): Illegal string offset 'leftLabel' at vendor\\vyuldashev\\xml-to-array\\src\\XmlToArray.php:87)
In my case, preg_replace helped me
$xml = file_get_contents('./res.xml');
$replaced= preg_replace('~<(?:!DOCTYPE|/?(?:html|body))[^>]*>\s*~', '', $xml);
But i am getting
PHP Warning: Illegal string offset 'i' in ..\php\vendor\vyuldashev\xml-to-array\src\XmlToArray.php on line 87