X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/c36df0c30a4fb6398823ab4b903054675953aba2..f20b2ef1a63ca42202fb063a1c0c3c06cb65e87e:/src/smartxml/smartxml.js diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 52236b6..d9e44be 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -268,17 +268,22 @@ $.extend(Document.prototype, Backbone.Events, { createDocumentNode: function(from) { if(!(from instanceof Node)) { - if(from.text !== undefined) { - /* globals document */ - from = document.createTextNode(from.text); + if(typeof from === 'string') { + from = parseXML(from); + this.normalizeXML(from); } else { - var node = $('<' + from.tagName + '>'); + if(from.text !== undefined) { + /* globals document */ + from = document.createTextNode(from.text); + } else { + var node = $('<' + from.tagName + '>'); - _.keys(from.attrs || {}).forEach(function(key) { - node.attr(key, from.attrs[key]); - }); + _.keys(from.attrs || {}).forEach(function(key) { + node.attr(key, from.attrs[key]); + }); - from = node[0]; + from = node[0]; + } } } var Factory, typeMethods, typeTransformations; @@ -309,11 +314,16 @@ $.extend(Document.prototype, Backbone.Events, { loadXML: function(xml, options) { options = options || {}; this._defineDocumentProperties($(parseXML(xml))); + this.normalizeXML(this.dom); if(!options.silent) { this.trigger('contentSet'); } }, + normalizeXML: function(nativeNode) { + void(nativeNode); // noop + }, + toXML: function() { return this.root.toXML(); },