CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: XML and Cookies

  1. #1
    Join Date
    Mar 2006
    Posts
    228

    Question XML and Cookies

    Hello,

    Just wondering if you can store a XML file into a Cookie?

    I have the following code:
    Code:
    function setCookie(c_name,value,exdays)
     {
     var exdate=new Date();
     exdate.setDate(exdate.getDate() + exdays);
     var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
     document.cookie=c_name + "=" + c_value;
     }
    just wondering if you can store a XML file into a cookie so that I can load the whole xml file from the cookie rather than loading the XML file again?

    Anyone able to help?

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: XML and Cookies

    Sorry. Cookies store raw strings. You could use JSON and serialize the XML as an object, then convert back to XML after. But, either way...you're still dealing with plain text.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    May 2012
    Posts
    3

    Re: XML and Cookies

    Agree with but you can set the timeout of the cookie. This is temporary solution yet.

  4. #4
    Join Date
    May 2012
    Location
    Bonn, Germany
    Posts
    43

    Re: XML and Cookies

    While you can store XML text in a cookie, it might not be the best idea.
    XML means a lot of overhead and if you want to store a lot of data, you can reach the 4 KB limit quickly.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured