Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WARNING 'SimpleXMLElement::addChild(): unterminated entity reference

Tags:

php

xml

Trying to create xml file and get warning.

WARNING 'SimpleXMLElement::addChild(): unterminated entity reference Brantford Jonson'

so when i try to open xml file get error

This page contains the following errors:

error on line 3 at column 4: StartTag: invalid element name
Below is a rendering of the page up to the first error.,

i think my error is related with this php warning.

here is relevant code

  if ($value instanceof Zend_Config) {
       $child = $xml->addChild($key);
       $this->_addBranch($value, $child, $xml);
      } else {

          $xml->addChild($key, (string) $value);
             }

can you help me to pin point why this error occurs. Tried something like this

if ($value instanceof Zend_Config) {
     $child = $xml->addChild($key);
      $this->_addBranch($value, $child, $xml);
  } else {     
       $xml->$key((string) htmlspecilalchars($value));
      }
like image 275
vladimirProp Avatar asked Apr 10 '17 14:04

vladimirProp


1 Answers

I ran across the error when there was an ampersand "&" in my XML. Maybe try escaping the string with htmlspecialchars().

like image 56
John Armstrong Avatar answered Sep 28 '22 03:09

John Armstrong