3 var XMLCData, XMLComment, XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDocType, XMLProcessingInstruction, create, isObject;
5 create = require(
'lodash/create');
7 isObject = require(
'lodash/isObject');
9 XMLCData = require(
'./XMLCData');
11 XMLComment = require(
'./XMLComment');
13 XMLDTDAttList = require(
'./XMLDTDAttList');
15 XMLDTDEntity = require(
'./XMLDTDEntity');
17 XMLDTDElement = require(
'./XMLDTDElement');
19 XMLDTDNotation = require(
'./XMLDTDNotation');
21 XMLProcessingInstruction = require(
'./XMLProcessingInstruction');
23 module.exports = XMLDocType = (
function() {
24 function XMLDocType(parent, pubID, sysID) {
26 this.documentObject = parent;
27 this.stringify = this.documentObject.stringify;
29 if (isObject(pubID)) {
30 ref = pubID, pubID = ref.pubID, sysID = ref.sysID;
33 ref1 = [pubID, sysID], sysID = ref1[0], pubID = ref1[1];
36 this.pubID = this.stringify.dtdPubID(pubID);
39 this.sysID = this.stringify.dtdSysID(sysID);
43 XMLDocType.prototype.element =
function(name, value) {
45 child =
new XMLDTDElement(
this, name, value);
46 this.children.push(child);
50 XMLDocType.prototype.attList =
function(elementName, attributeName, attributeType, defaultValueType, defaultValue) {
52 child =
new XMLDTDAttList(
this, elementName, attributeName, attributeType, defaultValueType, defaultValue);
53 this.children.push(child);
57 XMLDocType.prototype.entity =
function(name, value) {
59 child =
new XMLDTDEntity(
this,
false, name, value);
60 this.children.push(child);
64 XMLDocType.prototype.pEntity =
function(name, value) {
66 child =
new XMLDTDEntity(
this,
true, name, value);
67 this.children.push(child);
71 XMLDocType.prototype.notation =
function(name, value) {
73 child =
new XMLDTDNotation(
this, name, value);
74 this.children.push(child);
78 XMLDocType.prototype.cdata =
function(value) {
80 child =
new XMLCData(
this, value);
81 this.children.push(child);
85 XMLDocType.prototype.comment =
function(value) {
87 child =
new XMLComment(
this, value);
88 this.children.push(child);
92 XMLDocType.prototype.instruction =
function(target, value) {
94 child =
new XMLProcessingInstruction(
this, target, value);
95 this.children.push(child);
99 XMLDocType.prototype.root =
function() {
100 return this.documentObject.root();
103 XMLDocType.prototype.document =
function() {
104 return this.documentObject;
107 XMLDocType.prototype.toString =
function(options, level) {
108 var child, i, indent, len, newline, offset, pretty, r, ref, ref1, ref2, ref3, space;
109 pretty = (options != null ? options.pretty :
void 0) ||
false;
110 indent = (ref = options != null ? options.indent :
void 0) != null ? ref :
' ';
111 offset = (ref1 = options != null ? options.offset :
void 0) != null ? ref1 : 0;
112 newline = (ref2 = options != null ? options.newline :
void 0) != null ? ref2 :
'\n';
113 level || (level = 0);
114 space =
new Array(level + offset + 1).join(indent);
119 r +=
'<!DOCTYPE ' + this.root().name;
120 if (this.pubID && this.sysID) {
121 r +=
' PUBLIC "' + this.pubID +
'" "' + this.sysID +
'"';
122 }
else if (this.sysID) {
123 r +=
' SYSTEM "' + this.sysID +
'"';
125 if (this.children.length > 0) {
130 ref3 = this.children;
131 for (i = 0, len = ref3.length; i < len; i++) {
133 r += child.toString(options, level + 1);
144 XMLDocType.prototype.ele =
function(name, value) {
145 return this.element(name, value);
148 XMLDocType.prototype.att =
function(elementName, attributeName, attributeType, defaultValueType, defaultValue) {
149 return this.attList(elementName, attributeName, attributeType, defaultValueType, defaultValue);
152 XMLDocType.prototype.ent =
function(name, value) {
153 return this.entity(name, value);
156 XMLDocType.prototype.pent =
function(name, value) {
157 return this.pEntity(name, value);
160 XMLDocType.prototype.not =
function(name, value) {
161 return this.notation(name, value);
164 XMLDocType.prototype.dat =
function(value) {
165 return this.cdata(value);
168 XMLDocType.prototype.com =
function(value) {
169 return this.comment(value);
172 XMLDocType.prototype.ins =
function(target, value) {
173 return this.instruction(target, value);
176 XMLDocType.prototype.up =
function() {
180 XMLDocType.prototype.doc =
function() {
181 return this.document();