};
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];
- }});
+ this.loadXML(xml);
};
+
$.extend(Document.prototype, Backbone.Events, {
ElementNodeFactory: ElementNode,
TextNodeFactory: TextNode,
return new this.TextNodeFactory(nativeNode, this);
},
+ loadXML: function(xml) {
+ var $document = $(parseXML(xml));
+
+ var doc = this;
+ Object.defineProperty(this, 'root', {get: function() {
+ return doc.createElementNode($document[0]);
+ }, configurable: true});
+ Object.defineProperty(this, 'dom', {get: function() {
+ return $document[0];
+ }, configurable: true});
+
+ this.trigger('contentSet');
+ },
+
toXML: function() {
return this.root.toXML();
}
var doc = getDocumentFromXML('<div></div>');
expect(doc.root.getTagName()).to.equal('div');
});
+
+ it('can resets its content entirely', function() {
+ var doc = getDocumentFromXML('<div></div>');
+
+ expect(doc.root.getTagName()).to.equal('div');
+
+ doc.loadXML('<header></header>');
+ expect(doc.root.getTagName()).to.equal('header');
+ });
});
describe('Basic ElementNode properties', function() {