+});
+
+
+var parseXML = function(xml) {
+ return $(xml)[0];
+};
+
+var Document = function(xml) {
+ var $document = $(parseXML(xml));
+
+ var doc = this;
+ Object.defineProperty(this, 'root', {get: function() {
+ return doc.createElementNode($document[0]);
+ }});
+ Object.defineProperty(this, 'dom', {get: function() {
+ return $document[0];
+ }});
+};
+$.extend(Document.prototype, Backbone.Events, {
+ ElementNodeFactory: ElementNode,
+ TextNodeFactory: TextNode,
+
+ createElementNode: function(from) {
+ if(!(from instanceof HTMLElement)) {
+ from = $('<' + from.tagName + '>');
+ }
+ return new this.ElementNodeFactory(from, this);
+ },
+
+ createTextNode: function(nativeNode) {
+ return new this.TextNodeFactory(nativeNode, this);
+ },
+
+ toXML: function() {
+ return this.root.toXML();
+ }
+});