Click here to Skip to main content
15,906,569 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to cache a xsl object in local storage but when using JSON.stringify i catch an error "Converting circular structure to JSON ", how can i do this?
Posted
Comments
Sunasara Imdadhusen 9-May-14 0:18am    
Can you please provide code snippet for the same

1 solution

It is same as xml, here are the code:
C#
function XMLtoString(elem){

    var serialized;

    try {
        // XMLSerializer exists in current Mozilla browsers
        serializer = new XMLSerializer();
        serialized = serializer.serializeToString(elem);
    }
    catch (e) {
        // Internet Explorer has a different approach to serializing XML
        serialized = elem.xml;
    }

    return serialized;
}
function StringtoXML(text){
    if (window.ActiveXObject){
      var doc=new ActiveXObject('Microsoft.XMLDOM');
      doc.async='false';
      doc.loadXML(text);
    } else {
      var parser=new DOMParser();
      var doc=parser.parseFromString(text,'text/xml');
    }
    return doc;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900