xml-to-array icon indicating copy to clipboard operation
xml-to-array copied to clipboard

XmlToArray::convertDomElement() must be an instance of DOMElement, instance of DOMComment given

Open skalero01 opened this issue 5 years ago • 1 comments

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)

skalero01 avatar May 03 '19 16:05 skalero01

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

alaksandarjesus avatar Jul 01 '21 16:07 alaksandarjesus