1

I'm currently trying to generate XML using PHP and DOMDocument class.

// creating xml 'ServiceProfile'
           $xmlServiceProfile = new DOMDocument('1.0', 'utf-8');
           $xmlServiceProfile->formatOutput = true;
           $root = $xmlServiceProfile->createElement('*******');
               $serveur = $xmlServiceProfile->createElement('******', creeServeurLong(*****));
               $archive = $xmlServiceProfile->createElement('******', "******");

           $taskList = $xmlServiceProfile->createElement('******');

               foreach($array as $key => $value) {                   
                   $task = $xmlServiceProfile->createElement($key, $value);                   
                   $taskList->appendChild($task);
               }

           //adding nodes           
           $root->appendChild($******);
           $root->appendChild($******);
           $root->appendChild($******);
           $xmlServiceProfile->appendChild($root);            
           echo $xmlServiceProfile->saveXML();

I've got error that mean XML generation failed, but I have a good XML in my http response.

I checked the XML on a website and got

#65279;<?xml version="1.0" encoding="utf-8"?>

I already tryed to :

change document to UTF-8 without BOM, not working

Add trim() function on DOMDocument::saveXML()

Add htmlspecialchar() function on DOMDocument::saveXML()

Someone help please?

Robson
  • 813
  • 5
  • 21
  • 40
Rocaufeu
  • 66
  • 5
  • Why not use [XMLWriter](https://www.php.net/manual/en/book.xmlwriter.php) or [SimpleXML](https://www.php.net/manual/en/book.simplexml.php)? Both are robust XML parsing tools built into PHP and enabled by default. – tshimkus Mar 29 '19 at 09:02
  • Acutally, I never did it before and after google research, this way is most documented in my own language ^^ – Rocaufeu Mar 29 '19 at 09:47
  • Maybe this question might help: https://stackoverflow.com/questions/9691771/why-is-65279-appearing-in-my-html. That BOM is sneaking in there somehow. It could be related to your text editor somehow. Since it's a zero width space it can be tricky to spot. – tshimkus Mar 29 '19 at 10:02
  • Thanks, I already looked this, but it's not working on my case – Rocaufeu Mar 29 '19 at 10:21
  • Possible duplicate of [How to avoid echoing character 65279 in php?](https://stackoverflow.com/questions/6538203/how-to-avoid-echoing-character-65279-in-php-this-question-also-relates-to-java) – miken32 May 10 '19 at 18:43

0 Answers0