wlxml: moving white space handling from canvas code base
[fnpeditor.git] / src / smartxml / smartxml.js
index 6b71026..477166b 100644 (file)
@@ -9,6 +9,9 @@ var TEXT_NODE = Node.TEXT_NODE;
 
 
 var DocumentNode = function(nativeNode, document) {
+    if(!document) {
+        throw new Error('undefined document for a node');
+    }
     this.document = document;
     this.nativeNode = nativeNode;
     this._$ = $(nativeNode);
@@ -130,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 = $('<div>');
+        wrapper.append(this._$);
+        return wrapper.html();
+    }
 });
 
 var TextNode = function(nativeNode, document) {
@@ -166,6 +174,9 @@ var Document = function(xml) {
     Object.defineProperty(this, 'root', {get: function() {
         return doc.createElementNode($document[0]);
     }});
+    Object.defineProperty(this, 'dom', {get: function() {
+        return $document[0];
+    }});
 };
 $.extend(Document.prototype, {
     ElementNodeFactory: ElementNode,
@@ -177,6 +188,10 @@ $.extend(Document.prototype, {
 
     createTextNode: function(nativeNode) {
         return new this.TextNodeFactory(nativeNode, this);
+    },
+
+    toXML: function() {
+        return this.root.toXML();
     }
 });