00001
00002 (function() {
00003 var XMLDocument, XMLNode, XMLStringWriter, XMLStringifier, isPlainObject,
00004 extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
00005 hasProp = {}.hasOwnProperty;
00006
00007 isPlainObject = require('./Utility').isPlainObject;
00008
00009 XMLNode = require('./XMLNode');
00010
00011 XMLStringifier = require('./XMLStringifier');
00012
00013 XMLStringWriter = require('./XMLStringWriter');
00014
00015 module.exports = XMLDocument = (function(superClass) {
00016 extend(XMLDocument, superClass);
00017
00018 function XMLDocument(options) {
00019 XMLDocument.__super__.constructor.call(this, null);
00020 options || (options = {});
00021 if (!options.writer) {
00022 options.writer = new XMLStringWriter();
00023 }
00024 this.options = options;
00025 this.stringify = new XMLStringifier(options);
00026 this.isDocument = true;
00027 }
00028
00029 XMLDocument.prototype.end = function(writer) {
00030 var writerOptions;
00031 if (!writer) {
00032 writer = this.options.writer;
00033 } else if (isPlainObject(writer)) {
00034 writerOptions = writer;
00035 writer = this.options.writer.set(writerOptions);
00036 }
00037 return writer.document(this);
00038 };
00039
00040 XMLDocument.prototype.toString = function(options) {
00041 return this.options.writer.set(options).document(this);
00042 };
00043
00044 return XMLDocument;
00045
00046 })(XMLNode);
00047
00048 }).call(this);