Organizational Research By

Surprising Reserch Topic

generate xml out of textfile using json decode using -'php,json,xml,rss'


generate xml out of textfile using json decode  using -'php,json,xml,rss'

I have this Textfile (namelist.txt):


  {"0":"Mr Tony Test","1":"Ms Tina Testy"}


And I try to convert it into XML:

<?php
$xml = new DOMDocument();
$names = json_decode(file_get_contents('namelist.txt'));
foreach ($names as $name)
{
    $xml_name = $xml->createElement($name);

}
$xml->save("rss.xml");
?>


I get the following Error:


  Fatal error: Uncaught exception 'DOMException' with message 'Invalid
  Character Error' in C:\xampp\htdocs\xibo\rss.php:6 Stack trace: #0
  C:\xampp\htdocs\xibo\rss.php(6): DOMDocument->createElement('Mr  Tony
  Te...') #1 {main} thrown in C:\xampp\htdocs\xibo\rss.php on line 6


Is is even possible like this?
    
asked Sep 7, 2015 by rajesh
0 votes
15 views



Related Hot Questions



Government Jobs Opening


...