From: Aleksander Ɓukasz Date: Mon, 7 Oct 2013 13:50:55 +0000 (+0200) Subject: Simple smartxml.Document/ElementNode.toXML X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/921b131224a4b6210b8631c5ab7926304bcf3069 Simple smartxml.Document/ElementNode.toXML --- diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 1686abd..248333e 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -133,8 +133,13 @@ $.extend(ElementNode.prototype, DocumentNode.prototype, { element1: parent.contents()[myIdx + (moveLeftRange ? -1 : 0)], element2: parent.contents()[myIdx + childrenLength-1 + (moveRightRange ? 1 : 0)] }; - } + }, + toXML: function() { + var wrapper = $('
'); + wrapper.append(this._$); + return wrapper.html(); + } }); var TextNode = function(nativeNode, document) { @@ -180,6 +185,10 @@ $.extend(Document.prototype, { createTextNode: function(nativeNode) { return new this.TextNodeFactory(nativeNode, this); + }, + + toXML: function() { + return this.root.toXML(); } }); diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index bd1dfe4..6d6cbbf 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -85,6 +85,20 @@ describe('smartxml', function() { }); + describe('Serializing document to WLXML', function() { + it('keeps document intact when no changes have been made', function() { + var xmlIn = '
Alice
has
a cat!
', + doc = getDocumentFromXML(xmlIn), + xmlOut = doc.toXML(); + + var parser = new DOMParser(), + input = parser.parseFromString(xmlIn, 'application/xml').childNodes[0], + output = parser.parseFromString(xmlOut, 'application/xml').childNodes[0]; + + expect(input.isEqualNode(output)).to.be.true; + }); + }); + }); }); \ No newline at end of file