+});
+
+
+var parseXML = function(xml) {
+ return $(xml)[0];
+};
+
+var Document = function(xml) {
+ this.loadXML(xml);
+};
+
+$.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);
+ },
+
+ loadXML: function(xml) {
+ defineDocumentProperties(this, $(parseXML(xml)));
+
+ this.trigger('contentSet');
+ },
+
+ toXML: function() {
+ return this.root.toXML();
+ }
+});