+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]);
+ }});
+};
+$.extend(Document.prototype, {
+ ElementNodeFactory: ElementNode,
+ TextNodeFactory: TextNode,
+
+ createElementNode: function(nativeNode) {
+ return new this.ElementNodeFactory(nativeNode, this);
+ },
+
+ createTextNode: function(nativeNode) {
+ return new this.TextNodeFactory(nativeNode, this);
+ }
+});
+
+