demos/Collage/fabric.js
function loadSVGFromString(string, callback, reviver) {
    string = string.trim();
    var doc;
    if (typeof DOMParser !== 'undefined') {
      var parser = new DOMParser();
      if (parser && parser.parseFromString) {
        doc = parser.parseFromString(string, 'text/xml');
      }
    }
    else if (fabric.window.ActiveXObject) {
      var doc = new ActiveXObject('Microsoft.XMLDOM');
      doc.async = 'false';
      //IE chokes on DOCTYPE
      doc.loadXML(string.replace(/<!DOCTYPE[\s\S]*?(\[[\s\S]*\])*?>/i,''));
    }

    fabric.parseSVGDocument(doc.documentElement, function (results, options) {
      callback(results, options);
    }, reviver);
  }
function loadSVGFromString(string, callback, reviver) {
    string = string.trim();
    var doc;
    if (typeof DOMParser !== 'undefined') {
      var parser = new DOMParser();
      if (parser && parser.parseFromString) {
        doc = parser.parseFromString(string, 'text/xml');
      }
    }
    else if (fabric.window.ActiveXObject) {
      var doc = new ActiveXObject('Microsoft.XMLDOM');
      doc.async = 'false';
      //IE chokes on DOCTYPE
      doc.loadXML(string.replace(/<!DOCTYPE[\s\S]*?(\[[\s\S]*\])*?>/i,''));
    }

    fabric.parseSVGDocument(doc.documentElement, function (results, options) {
      callback(results, options);
    }, reviver);
  }
function loadSVGFromString ( string , callback , reviver ) { string = string . trim ( ) ; var doc ; if ( typeof DOMParser !== 'undefined' ) { var parser = new DOMParser ( ) ; if ( parser && parser . parseFromString ) { doc = parser . parseFromString ( string , 'text/xml' ) ; } } else if ( fabric . window . ActiveXObject ) { var doc = new ActiveXObject ( 'Microsoft.XMLDOM' ) ; doc . async = 'false' ; //IE chokes on DOCTYPE doc . loadXML ( string . replace ( / <!DOCTYPE[\s\S]*?(\[[\s\S]*\])*?> / i , '' ) ) ; } fabric . parseSVGDocument ( doc . documentElement , function ( results , options ) { callback ( results , options ) ; } , reviver ) ; }
Takes string corresponding to an SVG document, and parses it into a set of fabric objects
@method loadSVGFromString
@param {String} string
@param {Function} callback
@param {Function} [reviver] Method for further parsing of SVG elements, called after each fabric object created.
Takes string corresponding to an SVG document and parses it into a set of fabric objects