From 921b131224a4b6210b8631c5ab7926304bcf3069 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 7 Oct 2013 15:50:55 +0200 Subject: [PATCH] Simple smartxml.Document/ElementNode.toXML --- src/smartxml/smartxml.js | 11 ++++++++++- src/smartxml/smartxml.test.js | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) 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 -- 2.20.1