php - Write XML to file using JQuery AJAX -
i have write xml file , since way know javascript using ajax that's way i'm trying achieve it's been while since last used , i'm not being able parse text html codes characters instead of characters themselves.
what have:
ajax
$.ajax({ type: 'post', url: "writexml.php", datatype: 'xml', data: {filename: "test.xml", content: listxml}, error: function() { alert("unknown error. data not written file."); }, success: function() { window.open("test.xml"); } });
php file
<?php $filename = htmlspecialchars($_post["filename"]); $content = htmlspecialchars($_post["content"]); $file = fopen($filename, "w"); fwrite($file, $content); fclose($file); ?>
what trying achieve:
<?xml version="1.0" encoding="utf-8"?> <serieslist> <series> <title>ookami koushinryou</title> <score>6</score> <episodes>7</episodes> <episodestotal>23</episodestotal> <episodelength>20</episodelength> <timeswatched>dropped</timeswatched> </series> <series> <title>speed grapher</title> <score>5</score> <episodes>7</episodes> <episodestotal>24</episodestotal> <episodelength>20</episodelength> <timeswatched>dropped</timeswatched> </series> </serieslist>
what get:
<?xml version="1.0" encoding="utf-8"?> <serieslist> <series> <title>ookami koushinryou</title> <score>6</score> <episodes>7</episodes> <episodestotal>23</episodestotal> <episodelength>20</episodelength> <timeswatched>dropped</timeswatched> </series> <series> <title>speed grapher</title> <score>5</score> <episodes>7</episodes> <episodestotal>24</episodestotal> <episodelength>20</episodelength> <timeswatched>dropped</timeswatched> </series> </serieslist>
so can do? tried utf8_encode() did not work , i'm not you'd call versatile php i'm out of ideas.
i searched net thought of nothing worked far.
thanks in advance everything.
remove uses of htmlspecialchars
.
your file system doesn't use html express filenames, shouldn't convert filenames html. (you need sanitise filename though, @ moment letting people overwrite file on server!)
your xml data xml, couldn't convert html representation of xml.
Comments
Post a Comment