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:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt; &lt;serieslist&gt;     &lt;series&gt;  &lt;title&gt;ookami koushinryou&lt;/title&gt;  &lt;score&gt;6&lt;/score&gt;  &lt;episodes&gt;7&lt;/episodes&gt;  &lt;episodestotal&gt;23&lt;/episodestotal&gt;  &lt;episodelength&gt;20&lt;/episodelength&gt;  &lt;timeswatched&gt;dropped&lt;/timeswatched&gt; &lt;/series&gt;     &lt;series&gt;  &lt;title&gt;speed grapher&lt;/title&gt;  &lt;score&gt;5&lt;/score&gt;  &lt;episodes&gt;7&lt;/episodes&gt;  &lt;episodestotal&gt;24&lt;/episodestotal&gt;  &lt;episodelength&gt;20&lt;/episodelength&gt;  &lt;timeswatched&gt;dropped&lt;/timeswatched&gt; &lt;/series&gt;     &lt;/serieslist&gt; 

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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -