xml2js 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec_status +5 -0
  3. data/CODE_OF_CONDUCT.md +74 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +41 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +44 -0
  8. data/Rakefile +6 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/lib/xml2js.rb +5 -0
  12. data/lib/xml2js/node_modules/sax/LICENSE +41 -0
  13. data/lib/xml2js/node_modules/sax/README.md +225 -0
  14. data/lib/xml2js/node_modules/sax/lib/sax.js +1565 -0
  15. data/lib/xml2js/node_modules/sax/package.json +61 -0
  16. data/lib/xml2js/node_modules/xml2js/LICENSE +19 -0
  17. data/lib/xml2js/node_modules/xml2js/README.md +406 -0
  18. data/lib/xml2js/node_modules/xml2js/lib/bom.js +12 -0
  19. data/lib/xml2js/node_modules/xml2js/lib/builder.js +127 -0
  20. data/lib/xml2js/node_modules/xml2js/lib/defaults.js +72 -0
  21. data/lib/xml2js/node_modules/xml2js/lib/parser.js +357 -0
  22. data/lib/xml2js/node_modules/xml2js/lib/processors.js +34 -0
  23. data/lib/xml2js/node_modules/xml2js/lib/xml2js.js +37 -0
  24. data/lib/xml2js/node_modules/xml2js/package.json +280 -0
  25. data/lib/xml2js/node_modules/xmlbuilder/.npmignore +5 -0
  26. data/lib/xml2js/node_modules/xmlbuilder/CHANGELOG.md +423 -0
  27. data/lib/xml2js/node_modules/xmlbuilder/LICENSE +21 -0
  28. data/lib/xml2js/node_modules/xmlbuilder/README.md +85 -0
  29. data/lib/xml2js/node_modules/xmlbuilder/lib/Utility.js +73 -0
  30. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLAttribute.js +31 -0
  31. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLCData.js +32 -0
  32. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLComment.js +32 -0
  33. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDTDAttList.js +50 -0
  34. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDTDElement.js +35 -0
  35. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDTDEntity.js +56 -0
  36. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDTDNotation.js +37 -0
  37. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDeclaration.js +40 -0
  38. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDocType.js +107 -0
  39. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDocument.js +48 -0
  40. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDocumentCB.js +402 -0
  41. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLElement.js +111 -0
  42. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLNode.js +432 -0
  43. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLProcessingInstruction.js +35 -0
  44. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLRaw.js +32 -0
  45. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLStreamWriter.js +279 -0
  46. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLStringWriter.js +334 -0
  47. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLStringifier.js +163 -0
  48. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLText.js +32 -0
  49. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLWriterBase.js +90 -0
  50. data/lib/xml2js/node_modules/xmlbuilder/lib/index.js +53 -0
  51. data/lib/xml2js/node_modules/xmlbuilder/package.json +65 -0
  52. data/lib/xml2js/package-lock.json +25 -0
  53. data/lib/xml2js/parser.js +33 -0
  54. data/lib/xml2js/parser.rb +31 -0
  55. data/lib/xml2js/version.rb +3 -0
  56. data/xml2js.gemspec +30 -0
  57. metadata +154 -0
@@ -0,0 +1,35 @@
1
+ // Generated by CoffeeScript 1.12.7
2
+ (function() {
3
+ var XMLNode, XMLProcessingInstruction,
4
+ 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; },
5
+ hasProp = {}.hasOwnProperty;
6
+
7
+ XMLNode = require('./XMLNode');
8
+
9
+ module.exports = XMLProcessingInstruction = (function(superClass) {
10
+ extend(XMLProcessingInstruction, superClass);
11
+
12
+ function XMLProcessingInstruction(parent, target, value) {
13
+ XMLProcessingInstruction.__super__.constructor.call(this, parent);
14
+ if (target == null) {
15
+ throw new Error("Missing instruction target");
16
+ }
17
+ this.target = this.stringify.insTarget(target);
18
+ if (value) {
19
+ this.value = this.stringify.insValue(value);
20
+ }
21
+ }
22
+
23
+ XMLProcessingInstruction.prototype.clone = function() {
24
+ return Object.create(this);
25
+ };
26
+
27
+ XMLProcessingInstruction.prototype.toString = function(options) {
28
+ return this.options.writer.set(options).processingInstruction(this);
29
+ };
30
+
31
+ return XMLProcessingInstruction;
32
+
33
+ })(XMLNode);
34
+
35
+ }).call(this);
@@ -0,0 +1,32 @@
1
+ // Generated by CoffeeScript 1.12.7
2
+ (function() {
3
+ var XMLNode, XMLRaw,
4
+ 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; },
5
+ hasProp = {}.hasOwnProperty;
6
+
7
+ XMLNode = require('./XMLNode');
8
+
9
+ module.exports = XMLRaw = (function(superClass) {
10
+ extend(XMLRaw, superClass);
11
+
12
+ function XMLRaw(parent, text) {
13
+ XMLRaw.__super__.constructor.call(this, parent);
14
+ if (text == null) {
15
+ throw new Error("Missing raw text");
16
+ }
17
+ this.value = this.stringify.raw(text);
18
+ }
19
+
20
+ XMLRaw.prototype.clone = function() {
21
+ return Object.create(this);
22
+ };
23
+
24
+ XMLRaw.prototype.toString = function(options) {
25
+ return this.options.writer.set(options).raw(this);
26
+ };
27
+
28
+ return XMLRaw;
29
+
30
+ })(XMLNode);
31
+
32
+ }).call(this);
@@ -0,0 +1,279 @@
1
+ // Generated by CoffeeScript 1.12.7
2
+ (function() {
3
+ var XMLCData, XMLComment, XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDeclaration, XMLDocType, XMLElement, XMLProcessingInstruction, XMLRaw, XMLStreamWriter, XMLText, XMLWriterBase,
4
+ 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; },
5
+ hasProp = {}.hasOwnProperty;
6
+
7
+ XMLDeclaration = require('./XMLDeclaration');
8
+
9
+ XMLDocType = require('./XMLDocType');
10
+
11
+ XMLCData = require('./XMLCData');
12
+
13
+ XMLComment = require('./XMLComment');
14
+
15
+ XMLElement = require('./XMLElement');
16
+
17
+ XMLRaw = require('./XMLRaw');
18
+
19
+ XMLText = require('./XMLText');
20
+
21
+ XMLProcessingInstruction = require('./XMLProcessingInstruction');
22
+
23
+ XMLDTDAttList = require('./XMLDTDAttList');
24
+
25
+ XMLDTDElement = require('./XMLDTDElement');
26
+
27
+ XMLDTDEntity = require('./XMLDTDEntity');
28
+
29
+ XMLDTDNotation = require('./XMLDTDNotation');
30
+
31
+ XMLWriterBase = require('./XMLWriterBase');
32
+
33
+ module.exports = XMLStreamWriter = (function(superClass) {
34
+ extend(XMLStreamWriter, superClass);
35
+
36
+ function XMLStreamWriter(stream, options) {
37
+ XMLStreamWriter.__super__.constructor.call(this, options);
38
+ this.stream = stream;
39
+ }
40
+
41
+ XMLStreamWriter.prototype.document = function(doc) {
42
+ var child, i, j, len, len1, ref, ref1, results;
43
+ ref = doc.children;
44
+ for (i = 0, len = ref.length; i < len; i++) {
45
+ child = ref[i];
46
+ child.isLastRootNode = false;
47
+ }
48
+ doc.children[doc.children.length - 1].isLastRootNode = true;
49
+ ref1 = doc.children;
50
+ results = [];
51
+ for (j = 0, len1 = ref1.length; j < len1; j++) {
52
+ child = ref1[j];
53
+ switch (false) {
54
+ case !(child instanceof XMLDeclaration):
55
+ results.push(this.declaration(child));
56
+ break;
57
+ case !(child instanceof XMLDocType):
58
+ results.push(this.docType(child));
59
+ break;
60
+ case !(child instanceof XMLComment):
61
+ results.push(this.comment(child));
62
+ break;
63
+ case !(child instanceof XMLProcessingInstruction):
64
+ results.push(this.processingInstruction(child));
65
+ break;
66
+ default:
67
+ results.push(this.element(child));
68
+ }
69
+ }
70
+ return results;
71
+ };
72
+
73
+ XMLStreamWriter.prototype.attribute = function(att) {
74
+ return this.stream.write(' ' + att.name + '="' + att.value + '"');
75
+ };
76
+
77
+ XMLStreamWriter.prototype.cdata = function(node, level) {
78
+ return this.stream.write(this.space(level) + '<![CDATA[' + node.text + ']]>' + this.endline(node));
79
+ };
80
+
81
+ XMLStreamWriter.prototype.comment = function(node, level) {
82
+ return this.stream.write(this.space(level) + '<!-- ' + node.text + ' -->' + this.endline(node));
83
+ };
84
+
85
+ XMLStreamWriter.prototype.declaration = function(node, level) {
86
+ this.stream.write(this.space(level));
87
+ this.stream.write('<?xml version="' + node.version + '"');
88
+ if (node.encoding != null) {
89
+ this.stream.write(' encoding="' + node.encoding + '"');
90
+ }
91
+ if (node.standalone != null) {
92
+ this.stream.write(' standalone="' + node.standalone + '"');
93
+ }
94
+ this.stream.write(this.spacebeforeslash + '?>');
95
+ return this.stream.write(this.endline(node));
96
+ };
97
+
98
+ XMLStreamWriter.prototype.docType = function(node, level) {
99
+ var child, i, len, ref;
100
+ level || (level = 0);
101
+ this.stream.write(this.space(level));
102
+ this.stream.write('<!DOCTYPE ' + node.root().name);
103
+ if (node.pubID && node.sysID) {
104
+ this.stream.write(' PUBLIC "' + node.pubID + '" "' + node.sysID + '"');
105
+ } else if (node.sysID) {
106
+ this.stream.write(' SYSTEM "' + node.sysID + '"');
107
+ }
108
+ if (node.children.length > 0) {
109
+ this.stream.write(' [');
110
+ this.stream.write(this.endline(node));
111
+ ref = node.children;
112
+ for (i = 0, len = ref.length; i < len; i++) {
113
+ child = ref[i];
114
+ switch (false) {
115
+ case !(child instanceof XMLDTDAttList):
116
+ this.dtdAttList(child, level + 1);
117
+ break;
118
+ case !(child instanceof XMLDTDElement):
119
+ this.dtdElement(child, level + 1);
120
+ break;
121
+ case !(child instanceof XMLDTDEntity):
122
+ this.dtdEntity(child, level + 1);
123
+ break;
124
+ case !(child instanceof XMLDTDNotation):
125
+ this.dtdNotation(child, level + 1);
126
+ break;
127
+ case !(child instanceof XMLCData):
128
+ this.cdata(child, level + 1);
129
+ break;
130
+ case !(child instanceof XMLComment):
131
+ this.comment(child, level + 1);
132
+ break;
133
+ case !(child instanceof XMLProcessingInstruction):
134
+ this.processingInstruction(child, level + 1);
135
+ break;
136
+ default:
137
+ throw new Error("Unknown DTD node type: " + child.constructor.name);
138
+ }
139
+ }
140
+ this.stream.write(']');
141
+ }
142
+ this.stream.write(this.spacebeforeslash + '>');
143
+ return this.stream.write(this.endline(node));
144
+ };
145
+
146
+ XMLStreamWriter.prototype.element = function(node, level) {
147
+ var att, child, i, len, name, ref, ref1, space;
148
+ level || (level = 0);
149
+ space = this.space(level);
150
+ this.stream.write(space + '<' + node.name);
151
+ ref = node.attributes;
152
+ for (name in ref) {
153
+ if (!hasProp.call(ref, name)) continue;
154
+ att = ref[name];
155
+ this.attribute(att);
156
+ }
157
+ if (node.children.length === 0 || node.children.every(function(e) {
158
+ return e.value === '';
159
+ })) {
160
+ if (this.allowEmpty) {
161
+ this.stream.write('></' + node.name + '>');
162
+ } else {
163
+ this.stream.write(this.spacebeforeslash + '/>');
164
+ }
165
+ } else if (this.pretty && node.children.length === 1 && (node.children[0].value != null)) {
166
+ this.stream.write('>');
167
+ this.stream.write(node.children[0].value);
168
+ this.stream.write('</' + node.name + '>');
169
+ } else {
170
+ this.stream.write('>' + this.newline);
171
+ ref1 = node.children;
172
+ for (i = 0, len = ref1.length; i < len; i++) {
173
+ child = ref1[i];
174
+ switch (false) {
175
+ case !(child instanceof XMLCData):
176
+ this.cdata(child, level + 1);
177
+ break;
178
+ case !(child instanceof XMLComment):
179
+ this.comment(child, level + 1);
180
+ break;
181
+ case !(child instanceof XMLElement):
182
+ this.element(child, level + 1);
183
+ break;
184
+ case !(child instanceof XMLRaw):
185
+ this.raw(child, level + 1);
186
+ break;
187
+ case !(child instanceof XMLText):
188
+ this.text(child, level + 1);
189
+ break;
190
+ case !(child instanceof XMLProcessingInstruction):
191
+ this.processingInstruction(child, level + 1);
192
+ break;
193
+ default:
194
+ throw new Error("Unknown XML node type: " + child.constructor.name);
195
+ }
196
+ }
197
+ this.stream.write(space + '</' + node.name + '>');
198
+ }
199
+ return this.stream.write(this.endline(node));
200
+ };
201
+
202
+ XMLStreamWriter.prototype.processingInstruction = function(node, level) {
203
+ this.stream.write(this.space(level) + '<?' + node.target);
204
+ if (node.value) {
205
+ this.stream.write(' ' + node.value);
206
+ }
207
+ return this.stream.write(this.spacebeforeslash + '?>' + this.endline(node));
208
+ };
209
+
210
+ XMLStreamWriter.prototype.raw = function(node, level) {
211
+ return this.stream.write(this.space(level) + node.value + this.endline(node));
212
+ };
213
+
214
+ XMLStreamWriter.prototype.text = function(node, level) {
215
+ return this.stream.write(this.space(level) + node.value + this.endline(node));
216
+ };
217
+
218
+ XMLStreamWriter.prototype.dtdAttList = function(node, level) {
219
+ this.stream.write(this.space(level) + '<!ATTLIST ' + node.elementName + ' ' + node.attributeName + ' ' + node.attributeType);
220
+ if (node.defaultValueType !== '#DEFAULT') {
221
+ this.stream.write(' ' + node.defaultValueType);
222
+ }
223
+ if (node.defaultValue) {
224
+ this.stream.write(' "' + node.defaultValue + '"');
225
+ }
226
+ return this.stream.write(this.spacebeforeslash + '>' + this.endline(node));
227
+ };
228
+
229
+ XMLStreamWriter.prototype.dtdElement = function(node, level) {
230
+ this.stream.write(this.space(level) + '<!ELEMENT ' + node.name + ' ' + node.value);
231
+ return this.stream.write(this.spacebeforeslash + '>' + this.endline(node));
232
+ };
233
+
234
+ XMLStreamWriter.prototype.dtdEntity = function(node, level) {
235
+ this.stream.write(this.space(level) + '<!ENTITY');
236
+ if (node.pe) {
237
+ this.stream.write(' %');
238
+ }
239
+ this.stream.write(' ' + node.name);
240
+ if (node.value) {
241
+ this.stream.write(' "' + node.value + '"');
242
+ } else {
243
+ if (node.pubID && node.sysID) {
244
+ this.stream.write(' PUBLIC "' + node.pubID + '" "' + node.sysID + '"');
245
+ } else if (node.sysID) {
246
+ this.stream.write(' SYSTEM "' + node.sysID + '"');
247
+ }
248
+ if (node.nData) {
249
+ this.stream.write(' NDATA ' + node.nData);
250
+ }
251
+ }
252
+ return this.stream.write(this.spacebeforeslash + '>' + this.endline(node));
253
+ };
254
+
255
+ XMLStreamWriter.prototype.dtdNotation = function(node, level) {
256
+ this.stream.write(this.space(level) + '<!NOTATION ' + node.name);
257
+ if (node.pubID && node.sysID) {
258
+ this.stream.write(' PUBLIC "' + node.pubID + '" "' + node.sysID + '"');
259
+ } else if (node.pubID) {
260
+ this.stream.write(' PUBLIC "' + node.pubID + '"');
261
+ } else if (node.sysID) {
262
+ this.stream.write(' SYSTEM "' + node.sysID + '"');
263
+ }
264
+ return this.stream.write(this.spacebeforeslash + '>' + this.endline(node));
265
+ };
266
+
267
+ XMLStreamWriter.prototype.endline = function(node) {
268
+ if (!node.isLastRootNode) {
269
+ return this.newline;
270
+ } else {
271
+ return '';
272
+ }
273
+ };
274
+
275
+ return XMLStreamWriter;
276
+
277
+ })(XMLWriterBase);
278
+
279
+ }).call(this);
@@ -0,0 +1,334 @@
1
+ // Generated by CoffeeScript 1.12.7
2
+ (function() {
3
+ var XMLCData, XMLComment, XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDeclaration, XMLDocType, XMLElement, XMLProcessingInstruction, XMLRaw, XMLStringWriter, XMLText, XMLWriterBase,
4
+ 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; },
5
+ hasProp = {}.hasOwnProperty;
6
+
7
+ XMLDeclaration = require('./XMLDeclaration');
8
+
9
+ XMLDocType = require('./XMLDocType');
10
+
11
+ XMLCData = require('./XMLCData');
12
+
13
+ XMLComment = require('./XMLComment');
14
+
15
+ XMLElement = require('./XMLElement');
16
+
17
+ XMLRaw = require('./XMLRaw');
18
+
19
+ XMLText = require('./XMLText');
20
+
21
+ XMLProcessingInstruction = require('./XMLProcessingInstruction');
22
+
23
+ XMLDTDAttList = require('./XMLDTDAttList');
24
+
25
+ XMLDTDElement = require('./XMLDTDElement');
26
+
27
+ XMLDTDEntity = require('./XMLDTDEntity');
28
+
29
+ XMLDTDNotation = require('./XMLDTDNotation');
30
+
31
+ XMLWriterBase = require('./XMLWriterBase');
32
+
33
+ module.exports = XMLStringWriter = (function(superClass) {
34
+ extend(XMLStringWriter, superClass);
35
+
36
+ function XMLStringWriter(options) {
37
+ XMLStringWriter.__super__.constructor.call(this, options);
38
+ }
39
+
40
+ XMLStringWriter.prototype.document = function(doc) {
41
+ var child, i, len, r, ref;
42
+ this.textispresent = false;
43
+ r = '';
44
+ ref = doc.children;
45
+ for (i = 0, len = ref.length; i < len; i++) {
46
+ child = ref[i];
47
+ r += (function() {
48
+ switch (false) {
49
+ case !(child instanceof XMLDeclaration):
50
+ return this.declaration(child);
51
+ case !(child instanceof XMLDocType):
52
+ return this.docType(child);
53
+ case !(child instanceof XMLComment):
54
+ return this.comment(child);
55
+ case !(child instanceof XMLProcessingInstruction):
56
+ return this.processingInstruction(child);
57
+ default:
58
+ return this.element(child, 0);
59
+ }
60
+ }).call(this);
61
+ }
62
+ if (this.pretty && r.slice(-this.newline.length) === this.newline) {
63
+ r = r.slice(0, -this.newline.length);
64
+ }
65
+ return r;
66
+ };
67
+
68
+ XMLStringWriter.prototype.attribute = function(att) {
69
+ return ' ' + att.name + '="' + att.value + '"';
70
+ };
71
+
72
+ XMLStringWriter.prototype.cdata = function(node, level) {
73
+ return this.space(level) + '<![CDATA[' + node.text + ']]>' + this.newline;
74
+ };
75
+
76
+ XMLStringWriter.prototype.comment = function(node, level) {
77
+ return this.space(level) + '<!-- ' + node.text + ' -->' + this.newline;
78
+ };
79
+
80
+ XMLStringWriter.prototype.declaration = function(node, level) {
81
+ var r;
82
+ r = this.space(level);
83
+ r += '<?xml version="' + node.version + '"';
84
+ if (node.encoding != null) {
85
+ r += ' encoding="' + node.encoding + '"';
86
+ }
87
+ if (node.standalone != null) {
88
+ r += ' standalone="' + node.standalone + '"';
89
+ }
90
+ r += this.spacebeforeslash + '?>';
91
+ r += this.newline;
92
+ return r;
93
+ };
94
+
95
+ XMLStringWriter.prototype.docType = function(node, level) {
96
+ var child, i, len, r, ref;
97
+ level || (level = 0);
98
+ r = this.space(level);
99
+ r += '<!DOCTYPE ' + node.root().name;
100
+ if (node.pubID && node.sysID) {
101
+ r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
102
+ } else if (node.sysID) {
103
+ r += ' SYSTEM "' + node.sysID + '"';
104
+ }
105
+ if (node.children.length > 0) {
106
+ r += ' [';
107
+ r += this.newline;
108
+ ref = node.children;
109
+ for (i = 0, len = ref.length; i < len; i++) {
110
+ child = ref[i];
111
+ r += (function() {
112
+ switch (false) {
113
+ case !(child instanceof XMLDTDAttList):
114
+ return this.dtdAttList(child, level + 1);
115
+ case !(child instanceof XMLDTDElement):
116
+ return this.dtdElement(child, level + 1);
117
+ case !(child instanceof XMLDTDEntity):
118
+ return this.dtdEntity(child, level + 1);
119
+ case !(child instanceof XMLDTDNotation):
120
+ return this.dtdNotation(child, level + 1);
121
+ case !(child instanceof XMLCData):
122
+ return this.cdata(child, level + 1);
123
+ case !(child instanceof XMLComment):
124
+ return this.comment(child, level + 1);
125
+ case !(child instanceof XMLProcessingInstruction):
126
+ return this.processingInstruction(child, level + 1);
127
+ default:
128
+ throw new Error("Unknown DTD node type: " + child.constructor.name);
129
+ }
130
+ }).call(this);
131
+ }
132
+ r += ']';
133
+ }
134
+ r += this.spacebeforeslash + '>';
135
+ r += this.newline;
136
+ return r;
137
+ };
138
+
139
+ XMLStringWriter.prototype.element = function(node, level) {
140
+ var att, child, i, j, len, len1, name, r, ref, ref1, ref2, space, textispresentwasset;
141
+ level || (level = 0);
142
+ textispresentwasset = false;
143
+ if (this.textispresent) {
144
+ this.newline = '';
145
+ this.pretty = false;
146
+ } else {
147
+ this.newline = this.newlinedefault;
148
+ this.pretty = this.prettydefault;
149
+ }
150
+ space = this.space(level);
151
+ r = '';
152
+ r += space + '<' + node.name;
153
+ ref = node.attributes;
154
+ for (name in ref) {
155
+ if (!hasProp.call(ref, name)) continue;
156
+ att = ref[name];
157
+ r += this.attribute(att);
158
+ }
159
+ if (node.children.length === 0 || node.children.every(function(e) {
160
+ return e.value === '';
161
+ })) {
162
+ if (this.allowEmpty) {
163
+ r += '></' + node.name + '>' + this.newline;
164
+ } else {
165
+ r += this.spacebeforeslash + '/>' + this.newline;
166
+ }
167
+ } else if (this.pretty && node.children.length === 1 && (node.children[0].value != null)) {
168
+ r += '>';
169
+ r += node.children[0].value;
170
+ r += '</' + node.name + '>' + this.newline;
171
+ } else {
172
+ if (this.dontprettytextnodes) {
173
+ ref1 = node.children;
174
+ for (i = 0, len = ref1.length; i < len; i++) {
175
+ child = ref1[i];
176
+ if (child.value != null) {
177
+ this.textispresent++;
178
+ textispresentwasset = true;
179
+ break;
180
+ }
181
+ }
182
+ }
183
+ if (this.textispresent) {
184
+ this.newline = '';
185
+ this.pretty = false;
186
+ space = this.space(level);
187
+ }
188
+ r += '>' + this.newline;
189
+ ref2 = node.children;
190
+ for (j = 0, len1 = ref2.length; j < len1; j++) {
191
+ child = ref2[j];
192
+ r += (function() {
193
+ switch (false) {
194
+ case !(child instanceof XMLCData):
195
+ return this.cdata(child, level + 1);
196
+ case !(child instanceof XMLComment):
197
+ return this.comment(child, level + 1);
198
+ case !(child instanceof XMLElement):
199
+ return this.element(child, level + 1);
200
+ case !(child instanceof XMLRaw):
201
+ return this.raw(child, level + 1);
202
+ case !(child instanceof XMLText):
203
+ return this.text(child, level + 1);
204
+ case !(child instanceof XMLProcessingInstruction):
205
+ return this.processingInstruction(child, level + 1);
206
+ default:
207
+ throw new Error("Unknown XML node type: " + child.constructor.name);
208
+ }
209
+ }).call(this);
210
+ }
211
+ if (textispresentwasset) {
212
+ this.textispresent--;
213
+ }
214
+ if (!this.textispresent) {
215
+ this.newline = this.newlinedefault;
216
+ this.pretty = this.prettydefault;
217
+ }
218
+ r += space + '</' + node.name + '>' + this.newline;
219
+ }
220
+ return r;
221
+ };
222
+
223
+ XMLStringWriter.prototype.processingInstruction = function(node, level) {
224
+ var r;
225
+ r = this.space(level) + '<?' + node.target;
226
+ if (node.value) {
227
+ r += ' ' + node.value;
228
+ }
229
+ r += this.spacebeforeslash + '?>' + this.newline;
230
+ return r;
231
+ };
232
+
233
+ XMLStringWriter.prototype.raw = function(node, level) {
234
+ return this.space(level) + node.value + this.newline;
235
+ };
236
+
237
+ XMLStringWriter.prototype.text = function(node, level) {
238
+ return this.space(level) + node.value + this.newline;
239
+ };
240
+
241
+ XMLStringWriter.prototype.dtdAttList = function(node, level) {
242
+ var r;
243
+ r = this.space(level) + '<!ATTLIST ' + node.elementName + ' ' + node.attributeName + ' ' + node.attributeType;
244
+ if (node.defaultValueType !== '#DEFAULT') {
245
+ r += ' ' + node.defaultValueType;
246
+ }
247
+ if (node.defaultValue) {
248
+ r += ' "' + node.defaultValue + '"';
249
+ }
250
+ r += this.spacebeforeslash + '>' + this.newline;
251
+ return r;
252
+ };
253
+
254
+ XMLStringWriter.prototype.dtdElement = function(node, level) {
255
+ return this.space(level) + '<!ELEMENT ' + node.name + ' ' + node.value + this.spacebeforeslash + '>' + this.newline;
256
+ };
257
+
258
+ XMLStringWriter.prototype.dtdEntity = function(node, level) {
259
+ var r;
260
+ r = this.space(level) + '<!ENTITY';
261
+ if (node.pe) {
262
+ r += ' %';
263
+ }
264
+ r += ' ' + node.name;
265
+ if (node.value) {
266
+ r += ' "' + node.value + '"';
267
+ } else {
268
+ if (node.pubID && node.sysID) {
269
+ r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
270
+ } else if (node.sysID) {
271
+ r += ' SYSTEM "' + node.sysID + '"';
272
+ }
273
+ if (node.nData) {
274
+ r += ' NDATA ' + node.nData;
275
+ }
276
+ }
277
+ r += this.spacebeforeslash + '>' + this.newline;
278
+ return r;
279
+ };
280
+
281
+ XMLStringWriter.prototype.dtdNotation = function(node, level) {
282
+ var r;
283
+ r = this.space(level) + '<!NOTATION ' + node.name;
284
+ if (node.pubID && node.sysID) {
285
+ r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
286
+ } else if (node.pubID) {
287
+ r += ' PUBLIC "' + node.pubID + '"';
288
+ } else if (node.sysID) {
289
+ r += ' SYSTEM "' + node.sysID + '"';
290
+ }
291
+ r += this.spacebeforeslash + '>' + this.newline;
292
+ return r;
293
+ };
294
+
295
+ XMLStringWriter.prototype.openNode = function(node, level) {
296
+ var att, name, r, ref;
297
+ level || (level = 0);
298
+ if (node instanceof XMLElement) {
299
+ r = this.space(level) + '<' + node.name;
300
+ ref = node.attributes;
301
+ for (name in ref) {
302
+ if (!hasProp.call(ref, name)) continue;
303
+ att = ref[name];
304
+ r += this.attribute(att);
305
+ }
306
+ r += (node.children ? '>' : '/>') + this.newline;
307
+ return r;
308
+ } else {
309
+ r = this.space(level) + '<!DOCTYPE ' + node.rootNodeName;
310
+ if (node.pubID && node.sysID) {
311
+ r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
312
+ } else if (node.sysID) {
313
+ r += ' SYSTEM "' + node.sysID + '"';
314
+ }
315
+ r += (node.children ? ' [' : '>') + this.newline;
316
+ return r;
317
+ }
318
+ };
319
+
320
+ XMLStringWriter.prototype.closeNode = function(node, level) {
321
+ level || (level = 0);
322
+ switch (false) {
323
+ case !(node instanceof XMLElement):
324
+ return this.space(level) + '</' + node.name + '>' + this.newline;
325
+ case !(node instanceof XMLDocType):
326
+ return this.space(level) + ']>' + this.newline;
327
+ }
328
+ };
329
+
330
+ return XMLStringWriter;
331
+
332
+ })(XMLWriterBase);
333
+
334
+ }).call(this);