SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Saving XMLDocument through PHP

    i'm using AJAX to open an XML document. i'm editing this document via javascript. i've made my changes, and now i want to save the file through PHP.

    whats' the best way to do this?

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Send it to a PHP script on your server using AJAX, e.g. download.php. download.php then writes the string obtained via AJAX to a file (using file_put_contents() probably) and then forces the browser to download this file without exposing its actual location (using readfile() in a script similar to this).

  3. #3
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, i see what you're getting at. how can i turn my XML file, that i've pulled into javascript, back into a string?

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure what you mean. Anything involving AJAX uses strings, not files.

  5. #5
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when i open up the XML document, it is a string - but to be able to go loop through the tags, add/edit attributes, etc... i have to convert it to an XMLDocument. this i do using parseFromString().

    so now it's in XMLDocument form and i'm wanting to get it back to a string format - after i've edited the document.

  6. #6
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Can you use toString() for that? Give it a try, see if it results in a string.

  7. #7
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nah, i've tried that. all it seems to do is make "[object XMLDocument]" a string. literally. the output is "[object XMLDocument]".

  8. #8
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Maybe you just have to create a div somewhere, making it invisible with CSS, and append the XMLDocument to it. Then simply get the innerHTML of the div and there is the string. There should be a simpler way.


  9. #9
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here we go!

    Code JavaScript:
     // configFileXML is the XML Document
    var xml = new XMLSerializer();
    alert(xml.serializeToString(configFileXML));

    this works beautifully.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •