I am getting " EntityRef: expecting ';' error while creating xml through php "

762 Views Asked by At

This is my XML,I am using php code for creating this xml. Please see screenshot for code:enter image description here

<?xml version="1.0"?>
<LoggedErrors>
  <LoggedError>
  <DateTime>2018-03-30T10:28:28+00:00</DateTime>
  <Errors/>
  <Request>
    <FlightGroup>
      <ArrivalTime>
        <Hour>12</Hour>
        <Millisecond>0</Millisecond>
        <Minutes>20</Minutes>
        <Seconds>0</Seconds>
        <Day>12</Day>
        <DayOfWeek>Thursday</DayOfWeek>
        <Month>4</Month>
        <Year>2018</Year>
      </ArrivalTime>
    </FlightGroup>
   </Request>
 </LoggedError>
</LoggedErrors>
2

There are 2 best solutions below

0
Saurabh Khatri On BEST ANSWER
public  function printResult($raw_data){
    // adding Content Type
    header("Content-type: text/xml");
    // Converts PHP Array to XML with the root element being 'root-element-here'
    $xml = Excellence_Envision_Helper_Errorflile::createXML('LoggedError', $raw_data);

    return $xml->saveXML();

    }

Try to remove this code from your function and I think it will work fine then.

header("Content-type: text/xml");
0
Nehal Jain On

If the xml has special characters as values and ';' is not included it throws the error. For Example, if '<' is replaced with < and ';' after '&lt' is forgotten, browser (at least Chrome) displays the same error.