Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xmlbuilder

Package Overview
Dependencies
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xmlbuilder - npm Package Compare versions

Comparing version 10.1.1 to 11.0.0

.vs/ProjectSettings.json

32

CHANGELOG.md

@@ -5,2 +5,32 @@ # Change Log

## [11.0.0] - 2019-02-18
- Calling `end()` with arguments no longer overwrites writer options. See [#120](https://github.com/oozcitak/xmlbuilder-js/issues/120).
- Added writer state and customizable space and endline functions to help customize writer behavior. Also added `openNode` and `closeNode` functions to writer. See [#193](https://github.com/oozcitak/xmlbuilder-js/issues/193).
- Fixed a bug where writer functions would not be called for nodes with a single child node in pretty print mode. See [#195](https://github.com/oozcitak/xmlbuilder-js/issues/195).
- Renamed `elEscape` to `textEscape` in `XMLStringifier`.
- Fixed a bug where empty arrays would produce child nodes. See [#190](https://github.com/oozcitak/xmlbuilder-js/issues/190).
- Removed the `skipNullAttributes` option. `null` attributes are now skipped by default. Added the `keepNullAttributes` option in case someone needs the old behavior.
- Removed the `skipNullNodes` option. `null` nodes are now skipped by default. Added the `keepNullNodes` option in case someone needs the old behavior.
- `undefined` values are now skipped when converting JS objects.
- Renamed stringify functions. See [#194](https://github.com/oozcitak/xmlbuilder-js/issues/194):
* `eleName` -> `name`
* `attName` -> `name`
* `eleText` -> `text`
- Fixed argument order for `attribute` function in the writer. See [#196](https://github.com/oozcitak/xmlbuilder-js/issues/196).
- Added `openAttribute` and `closeAttribute` functions to writer. See [#196](https://github.com/oozcitak/xmlbuilder-js/issues/196).
- Added node types to node objects. Node types and writer states are exported by the module with the `nodeType` and `writerState` properties.
- Fixed a bug where array items would not be correctly converted. See [#159](https://github.com/oozcitak/xmlbuilder-js/issues/159).
- Fixed a bug where mixed-content inside JS objects with `#text` decorator would not be correctly converted. See [#171](https://github.com/oozcitak/xmlbuilder-js/issues/171).
- Fixed a bug where JS objects would not be expanded in callback mode. See [#173](https://github.com/oozcitak/xmlbuilder-js/issues/173).
- Fixed a bug where character validation would not obey document's XML version. Added separate validation for XML 1.0 and XML 1.1 documents. See [#169](https://github.com/oozcitak/xmlbuilder-js/issues/169).
- Fixed a bug where names would not be validated according to the spec. See [#49](https://github.com/oozcitak/xmlbuilder-js/issues/49).
- Renamed `text` property to `value` in comment and cdata nodes to unify the API.
- Removed `doctype` function to prevent name clash with DOM implementation. Use the `dtd` function instead.
- Removed dummy nodes from the XML tree (Those were created while chain-building the tree).
- Renamed `attributes`property to `attribs` to prevent name clash with DOM property with the same name.
- Implemented the DOM standard (read-only) to support XPath lookups. XML namespaces are not currently supported. See [#122](https://github.com/oozcitak/xmlbuilder-js/issues/122).
## [10.1.1] - 2018-10-24
- Fixed an edge case where a null node at root level would be printed although `skipNullNodes` was set. See [#187](https://github.com/oozcitak/xmlbuilder-js/issues/187).
## [10.1.0] - 2018-10-10

@@ -361,2 +391,4 @@ - Added the `skipNullNodes` option to skip nodes with null values. See [#158](https://github.com/oozcitak/xmlbuilder-js/issues/158).

[11.0.0]: https://github.com/oozcitak/xmlbuilder-js/compare/v10.1.1...v11.0.0
[10.1.1]: https://github.com/oozcitak/xmlbuilder-js/compare/v10.1.0...v10.1.1
[10.1.0]: https://github.com/oozcitak/xmlbuilder-js/compare/v10.0.0...v10.1.0

@@ -363,0 +395,0 @@ [10.0.0]: https://github.com/oozcitak/xmlbuilder-js/compare/v9.0.7...v10.0.0

16

lib/index.js
// Generated by CoffeeScript 1.12.7
(function() {
var XMLDocument, XMLDocumentCB, XMLStreamWriter, XMLStringWriter, assign, isFunction, ref;
var NodeType, WriterState, XMLDOMImplementation, XMLDocument, XMLDocumentCB, XMLStreamWriter, XMLStringWriter, assign, isFunction, ref;
ref = require('./Utility'), assign = ref.assign, isFunction = ref.isFunction;
XMLDOMImplementation = require('./XMLDOMImplementation');
XMLDocument = require('./XMLDocument');

@@ -15,2 +17,6 @@

NodeType = require('./NodeType');
WriterState = require('./WriterState');
module.exports.create = function(name, xmldec, doctype, options) {

@@ -27,3 +33,3 @@ var doc, root;

if ((options.pubID != null) || (options.sysID != null)) {
doc.doctype(options);
doc.dtd(options);
}

@@ -55,2 +61,8 @@ }

module.exports.implementation = new XMLDOMImplementation();
module.exports.nodeType = NodeType;
module.exports.writerState = WriterState;
}).call(this);
// Generated by CoffeeScript 1.12.7
(function() {
var XMLAttribute;
var NodeType, XMLAttribute, XMLNode;
NodeType = require('./NodeType');
XMLNode = require('./XMLNode');
module.exports = XMLAttribute = (function() {
function XMLAttribute(parent, name, value) {
this.options = parent.options;
this.stringify = parent.stringify;
this.parent = parent;
if (this.parent) {
this.options = this.parent.options;
this.stringify = this.parent.stringify;
}
if (name == null) {
throw new Error("Missing attribute name. " + this.debugInfo(name));
}
if (value == null) {
throw new Error("Missing attribute value. " + this.debugInfo(name));
}
this.name = this.stringify.attName(name);
this.name = this.stringify.name(name);
this.value = this.stringify.attValue(value);
this.type = NodeType.Attribute;
this.isId = false;
this.schemaTypeInfo = null;
}
Object.defineProperty(XMLAttribute.prototype, 'nodeType', {
get: function() {
return this.type;
}
});
Object.defineProperty(XMLAttribute.prototype, 'ownerElement', {
get: function() {
return this.parent;
}
});
Object.defineProperty(XMLAttribute.prototype, 'textContent', {
get: function() {
return this.value;
},
set: function(value) {
return this.value = value || '';
}
});
Object.defineProperty(XMLAttribute.prototype, 'namespaceURI', {
get: function() {
return '';
}
});
Object.defineProperty(XMLAttribute.prototype, 'prefix', {
get: function() {
return '';
}
});
Object.defineProperty(XMLAttribute.prototype, 'localName', {
get: function() {
return this.name;
}
});
Object.defineProperty(XMLAttribute.prototype, 'specified', {
get: function() {
return true;
}
});
XMLAttribute.prototype.clone = function() {

@@ -25,3 +76,3 @@ return Object.create(this);

XMLAttribute.prototype.toString = function(options) {
return this.options.writer.set(options).attribute(this);
return this.options.writer.attribute(this, this.options.writer.filterOptions(options));
};

@@ -38,2 +89,18 @@

XMLAttribute.prototype.isEqualNode = function(node) {
if (node.namespaceURI !== this.namespaceURI) {
return false;
}
if (node.prefix !== this.prefix) {
return false;
}
if (node.localName !== this.localName) {
return false;
}
if (node.value !== this.value) {
return false;
}
return true;
};
return XMLAttribute;

@@ -40,0 +107,0 @@

14

lib/XMLCData.js
// Generated by CoffeeScript 1.12.7
(function() {
var XMLCData, XMLNode,
var NodeType, XMLCData, XMLCharacterData,
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; },
hasProp = {}.hasOwnProperty;
XMLNode = require('./XMLNode');
NodeType = require('./NodeType');
XMLCharacterData = require('./XMLCharacterData');
module.exports = XMLCData = (function(superClass) {

@@ -17,3 +19,5 @@ extend(XMLCData, superClass);

}
this.text = this.stringify.cdata(text);
this.name = "#cdata-section";
this.type = NodeType.CData;
this.value = this.stringify.cdata(text);
}

@@ -26,3 +30,3 @@

XMLCData.prototype.toString = function(options) {
return this.options.writer.set(options).cdata(this);
return this.options.writer.cdata(this, this.options.writer.filterOptions(options));
};

@@ -32,4 +36,4 @@

})(XMLNode);
})(XMLCharacterData);
}).call(this);
// Generated by CoffeeScript 1.12.7
(function() {
var XMLComment, XMLNode,
var NodeType, XMLCharacterData, XMLComment,
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; },
hasProp = {}.hasOwnProperty;
XMLNode = require('./XMLNode');
NodeType = require('./NodeType');
XMLCharacterData = require('./XMLCharacterData');
module.exports = XMLComment = (function(superClass) {

@@ -17,3 +19,5 @@ extend(XMLComment, superClass);

}
this.text = this.stringify.comment(text);
this.name = "#comment";
this.type = NodeType.Comment;
this.value = this.stringify.comment(text);
}

@@ -26,3 +30,3 @@

XMLComment.prototype.toString = function(options) {
return this.options.writer.set(options).comment(this);
return this.options.writer.comment(this, this.options.writer.filterOptions(options));
};

@@ -32,4 +36,4 @@

})(XMLNode);
})(XMLCharacterData);
}).call(this);
// Generated by CoffeeScript 1.12.7
(function() {
var XMLDeclaration, XMLNode, isObject,
var NodeType, XMLDeclaration, XMLNode, isObject,
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; },

@@ -11,2 +11,4 @@ hasProp = {}.hasOwnProperty;

NodeType = require('./NodeType');
module.exports = XMLDeclaration = (function(superClass) {

@@ -24,2 +26,3 @@ extend(XMLDeclaration, superClass);

}
this.type = NodeType.Declaration;
this.version = this.stringify.xmlVersion(version);

@@ -35,3 +38,3 @@ if (encoding != null) {

XMLDeclaration.prototype.toString = function(options) {
return this.options.writer.set(options).declaration(this);
return this.options.writer.declaration(this, this.options.writer.filterOptions(options));
};

@@ -38,0 +41,0 @@

// Generated by CoffeeScript 1.12.7
(function() {
var XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDocType, XMLNode, isObject,
var NodeType, XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDocType, XMLNamedNodeMap, XMLNode, isObject,
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; },

@@ -11,2 +11,4 @@ hasProp = {}.hasOwnProperty;

NodeType = require('./NodeType');
XMLDTDAttList = require('./XMLDTDAttList');

@@ -20,2 +22,4 @@

XMLNamedNodeMap = require('./XMLNamedNodeMap');
module.exports = XMLDocType = (function(superClass) {

@@ -25,11 +29,21 @@ extend(XMLDocType, superClass);

function XMLDocType(parent, pubID, sysID) {
var ref, ref1;
var child, i, len, ref, ref1, ref2;
XMLDocType.__super__.constructor.call(this, parent);
this.name = "!DOCTYPE";
this.type = NodeType.DocType;
if (parent.children) {
ref = parent.children;
for (i = 0, len = ref.length; i < len; i++) {
child = ref[i];
if (child.type === NodeType.Element) {
this.name = child.name;
break;
}
}
}
this.documentObject = parent;
if (isObject(pubID)) {
ref = pubID, pubID = ref.pubID, sysID = ref.sysID;
ref1 = pubID, pubID = ref1.pubID, sysID = ref1.sysID;
}
if (sysID == null) {
ref1 = [pubID, sysID], sysID = ref1[0], pubID = ref1[1];
ref2 = [pubID, sysID], sysID = ref2[0], pubID = ref2[1];
}

@@ -44,2 +58,50 @@ if (pubID != null) {

Object.defineProperty(XMLDocType.prototype, 'entities', {
get: function() {
var child, i, len, nodes, ref;
nodes = {};
ref = this.children;
for (i = 0, len = ref.length; i < len; i++) {
child = ref[i];
if ((child.type === NodeType.EntityDeclaration) && !child.pe) {
nodes[child.name] = child;
}
}
return new XMLNamedNodeMap(nodes);
}
});
Object.defineProperty(XMLDocType.prototype, 'notations', {
get: function() {
var child, i, len, nodes, ref;
nodes = {};
ref = this.children;
for (i = 0, len = ref.length; i < len; i++) {
child = ref[i];
if (child.type === NodeType.NotationDeclaration) {
nodes[child.name] = child;
}
}
return new XMLNamedNodeMap(nodes);
}
});
Object.defineProperty(XMLDocType.prototype, 'publicId', {
get: function() {
return this.pubID;
}
});
Object.defineProperty(XMLDocType.prototype, 'systemId', {
get: function() {
return this.sysID;
}
});
Object.defineProperty(XMLDocType.prototype, 'internalSubset', {
get: function() {
throw new Error("This DOM method is not implemented." + this.debugInfo());
}
});
XMLDocType.prototype.element = function(name, value) {

@@ -81,3 +143,3 @@ var child;

XMLDocType.prototype.toString = function(options) {
return this.options.writer.set(options).docType(this);
return this.options.writer.docType(this, this.options.writer.filterOptions(options));
};

@@ -109,2 +171,18 @@

XMLDocType.prototype.isEqualNode = function(node) {
if (!XMLDocType.__super__.isEqualNode.apply(this, arguments).isEqualNode(node)) {
return false;
}
if (node.name !== this.name) {
return false;
}
if (node.publicId !== this.publicId) {
return false;
}
if (node.systemId !== this.systemId) {
return false;
}
return true;
};
return XMLDocType;

@@ -111,0 +189,0 @@

// Generated by CoffeeScript 1.12.7
(function() {
var XMLDocument, XMLNode, XMLStringWriter, XMLStringifier, isPlainObject,
var NodeType, XMLDOMConfiguration, XMLDOMImplementation, XMLDocument, XMLNode, XMLStringWriter, XMLStringifier, isPlainObject,
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; },

@@ -9,4 +9,10 @@ hasProp = {}.hasOwnProperty;

XMLDOMImplementation = require('./XMLDOMImplementation');
XMLDOMConfiguration = require('./XMLDOMConfiguration');
XMLNode = require('./XMLNode');
NodeType = require('./NodeType');
XMLStringifier = require('./XMLStringifier');

@@ -21,3 +27,6 @@

XMLDocument.__super__.constructor.call(this, null);
this.name = "?xml";
this.name = "#document";
this.type = NodeType.Document;
this.documentURI = null;
this.domConfig = new XMLDOMConfiguration();
options || (options = {});

@@ -29,7 +38,103 @@ if (!options.writer) {

this.stringify = new XMLStringifier(options);
this.isDocument = true;
}
Object.defineProperty(XMLDocument.prototype, 'implementation', {
value: new XMLDOMImplementation()
});
Object.defineProperty(XMLDocument.prototype, 'doctype', {
get: function() {
var child, i, len, ref;
ref = this.children;
for (i = 0, len = ref.length; i < len; i++) {
child = ref[i];
if (child.type === NodeType.DocType) {
return child;
}
}
return null;
}
});
Object.defineProperty(XMLDocument.prototype, 'documentElement', {
get: function() {
return this.rootObject || null;
}
});
Object.defineProperty(XMLDocument.prototype, 'inputEncoding', {
get: function() {
return null;
}
});
Object.defineProperty(XMLDocument.prototype, 'strictErrorChecking', {
get: function() {
return false;
}
});
Object.defineProperty(XMLDocument.prototype, 'xmlEncoding', {
get: function() {
if (this.children.length !== 0 && this.children[0].type === NodeType.Declaration) {
return this.children[0].encoding;
} else {
return null;
}
}
});
Object.defineProperty(XMLDocument.prototype, 'xmlStandalone', {
get: function() {
if (this.children.length !== 0 && this.children[0].type === NodeType.Declaration) {
return this.children[0].standalone === 'yes';
} else {
return false;
}
}
});
Object.defineProperty(XMLDocument.prototype, 'xmlVersion', {
get: function() {
if (this.children.length !== 0 && this.children[0].type === NodeType.Declaration) {
return this.children[0].version;
} else {
return "1.0";
}
}
});
Object.defineProperty(XMLDocument.prototype, 'URL', {
get: function() {
return this.documentURI;
}
});
Object.defineProperty(XMLDocument.prototype, 'origin', {
get: function() {
return null;
}
});
Object.defineProperty(XMLDocument.prototype, 'compatMode', {
get: function() {
return null;
}
});
Object.defineProperty(XMLDocument.prototype, 'characterSet', {
get: function() {
return null;
}
});
Object.defineProperty(XMLDocument.prototype, 'contentType', {
get: function() {
return null;
}
});
XMLDocument.prototype.end = function(writer) {
var writerOptions;
writerOptions = {};
if (!writer) {

@@ -39,11 +144,99 @@ writer = this.options.writer;

writerOptions = writer;
writer = this.options.writer.set(writerOptions);
writer = this.options.writer;
}
return writer.document(this);
return writer.document(this, writer.filterOptions(writerOptions));
};
XMLDocument.prototype.toString = function(options) {
return this.options.writer.set(options).document(this);
return this.options.writer.document(this, this.options.writer.filterOptions(options));
};
XMLDocument.prototype.createElement = function(tagName) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.createDocumentFragment = function() {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.createTextNode = function(data) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.createComment = function(data) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.createCDATASection = function(data) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.createProcessingInstruction = function(target, data) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.createAttribute = function(name) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.createEntityReference = function(name) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.getElementsByTagName = function(tagname) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.importNode = function(importedNode, deep) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.createElementNS = function(namespaceURI, qualifiedName) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.createAttributeNS = function(namespaceURI, qualifiedName) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.getElementsByTagNameNS = function(namespaceURI, localName) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.getElementById = function(elementId) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.adoptNode = function(source) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.normalizeDocument = function() {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.renameNode = function(node, namespaceURI, qualifiedName) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.getElementsByClassName = function(classNames) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.createEvent = function(eventInterface) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.createRange = function() {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.createNodeIterator = function(root, whatToShow, filter) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLDocument.prototype.createTreeWalker = function(root, whatToShow, filter) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
return XMLDocument;

@@ -50,0 +243,0 @@

// Generated by CoffeeScript 1.12.7
(function() {
var XMLAttribute, XMLCData, XMLComment, XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDeclaration, XMLDocType, XMLDocumentCB, XMLElement, XMLProcessingInstruction, XMLRaw, XMLStringWriter, XMLStringifier, XMLText, getValue, isFunction, isObject, isPlainObject, ref,
var NodeType, WriterState, XMLAttribute, XMLCData, XMLComment, XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDeclaration, XMLDocType, XMLDocument, XMLDocumentCB, XMLElement, XMLProcessingInstruction, XMLRaw, XMLStringWriter, XMLStringifier, XMLText, getValue, isFunction, isObject, isPlainObject, ref,
hasProp = {}.hasOwnProperty;

@@ -8,2 +8,6 @@

NodeType = require('./NodeType');
XMLDocument = require('./XMLDocument');
XMLElement = require('./XMLElement');

@@ -39,2 +43,4 @@

WriterState = require('./WriterState');
module.exports = XMLDocumentCB = (function() {

@@ -44,11 +50,14 @@ function XMLDocumentCB(options, onData, onEnd) {

this.name = "?xml";
this.type = NodeType.Document;
options || (options = {});
writerOptions = {};
if (!options.writer) {
options.writer = new XMLStringWriter(options);
options.writer = new XMLStringWriter();
} else if (isPlainObject(options.writer)) {
writerOptions = options.writer;
options.writer = new XMLStringWriter(writerOptions);
options.writer = new XMLStringWriter();
}
this.options = options;
this.writer = options.writer;
this.writerOptions = this.writer.filterOptions(writerOptions);
this.stringify = new XMLStringifier(options);

@@ -65,4 +74,53 @@ this.onDataCallback = onData || function() {};

XMLDocumentCB.prototype.createChildNode = function(node) {
var att, attName, attributes, child, i, len, ref1, ref2;
switch (node.type) {
case NodeType.CData:
this.cdata(node.value);
break;
case NodeType.Comment:
this.comment(node.value);
break;
case NodeType.Element:
attributes = {};
ref1 = node.attribs;
for (attName in ref1) {
if (!hasProp.call(ref1, attName)) continue;
att = ref1[attName];
attributes[attName] = att.value;
}
this.node(node.name, attributes);
break;
case NodeType.Dummy:
this.dummy();
break;
case NodeType.Raw:
this.raw(node.value);
break;
case NodeType.Text:
this.text(node.value);
break;
case NodeType.ProcessingInstruction:
this.instruction(node.target, node.value);
break;
default:
throw new Error("This XML node type is not supported in a JS object: " + node.constructor.name);
}
ref2 = node.children;
for (i = 0, len = ref2.length; i < len; i++) {
child = ref2[i];
this.createChildNode(child);
if (child.type === NodeType.Element) {
this.up();
}
}
return this;
};
XMLDocumentCB.prototype.dummy = function() {
return this;
};
XMLDocumentCB.prototype.node = function(name, attributes, text) {
var ref1, ref2;
var ref1;
if (name == null) {

@@ -76,5 +134,2 @@ throw new Error("Missing node name.");

name = getValue(name);
if (attributes === null && (text == null)) {
ref1 = [{}, null], attributes = ref1[0], text = ref1[1];
}
if (attributes == null) {

@@ -85,3 +140,3 @@ attributes = {};

if (!isObject(attributes)) {
ref2 = [attributes, text], text = ref2[0], attributes = ref2[1];
ref1 = [attributes, text], text = ref1[0], attributes = ref1[1];
}

@@ -99,7 +154,25 @@ this.currentNode = new XMLElement(this, name, attributes);

XMLDocumentCB.prototype.element = function(name, attributes, text) {
if (this.currentNode && this.currentNode instanceof XMLDocType) {
return this.dtdElement.apply(this, arguments);
var child, i, len, oldValidationFlag, ref1, root;
if (this.currentNode && this.currentNode.type === NodeType.DocType) {
this.dtdElement.apply(this, arguments);
} else {
return this.node(name, attributes, text);
if (Array.isArray(name) || isObject(name) || isFunction(name)) {
oldValidationFlag = this.options.noValidation;
this.options.noValidation = true;
root = new XMLDocument(this.options).element('TEMP_ROOT');
root.element(name);
this.options.noValidation = oldValidationFlag;
ref1 = root.children;
for (i = 0, len = ref1.length; i < len; i++) {
child = ref1[i];
this.createChildNode(child);
if (child.type === NodeType.Element) {
this.up();
}
}
} else {
this.node(name, attributes, text);
}
}
return this;
};

@@ -125,4 +198,6 @@

}
if (!this.options.skipNullAttributes || (value != null)) {
this.currentNode.attributes[name] = new XMLAttribute(this, name, value);
if (this.options.keepNullAttributes && (value == null)) {
this.currentNode.attribs[name] = new XMLAttribute(this, name, "");
} else if (value != null) {
this.currentNode.attribs[name] = new XMLAttribute(this, name, value);
}

@@ -137,3 +212,3 @@ }

node = new XMLText(this, value);
this.onData(this.writer.text(node, this.currentLevel + 1), this.currentLevel + 1);
this.onData(this.writer.text(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
return this;

@@ -146,3 +221,3 @@ };

node = new XMLCData(this, value);
this.onData(this.writer.cdata(node, this.currentLevel + 1), this.currentLevel + 1);
this.onData(this.writer.cdata(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
return this;

@@ -155,3 +230,3 @@ };

node = new XMLComment(this, value);
this.onData(this.writer.comment(node, this.currentLevel + 1), this.currentLevel + 1);
this.onData(this.writer.comment(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
return this;

@@ -164,3 +239,3 @@ };

node = new XMLRaw(this, value);
this.onData(this.writer.raw(node, this.currentLevel + 1), this.currentLevel + 1);
this.onData(this.writer.raw(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
return this;

@@ -194,3 +269,3 @@ };

node = new XMLProcessingInstruction(this, target, value);
this.onData(this.writer.processingInstruction(node, this.currentLevel + 1), this.currentLevel + 1);
this.onData(this.writer.processingInstruction(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
}

@@ -207,3 +282,3 @@ return this;

node = new XMLDeclaration(this, version, encoding, standalone);
this.onData(this.writer.declaration(node, this.currentLevel + 1), this.currentLevel + 1);
this.onData(this.writer.declaration(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
return this;

@@ -232,3 +307,3 @@ };

node = new XMLDTDElement(this, name, value);
this.onData(this.writer.dtdElement(node, this.currentLevel + 1), this.currentLevel + 1);
this.onData(this.writer.dtdElement(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
return this;

@@ -241,3 +316,3 @@ };

node = new XMLDTDAttList(this, elementName, attributeName, attributeType, defaultValueType, defaultValue);
this.onData(this.writer.dtdAttList(node, this.currentLevel + 1), this.currentLevel + 1);
this.onData(this.writer.dtdAttList(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
return this;

@@ -250,3 +325,3 @@ };

node = new XMLDTDEntity(this, false, name, value);
this.onData(this.writer.dtdEntity(node, this.currentLevel + 1), this.currentLevel + 1);
this.onData(this.writer.dtdEntity(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
return this;

@@ -259,3 +334,3 @@ };

node = new XMLDTDEntity(this, true, name, value);
this.onData(this.writer.dtdEntity(node, this.currentLevel + 1), this.currentLevel + 1);
this.onData(this.writer.dtdEntity(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
return this;

@@ -268,3 +343,3 @@ };

node = new XMLDTDNotation(this, name, value);
this.onData(this.writer.dtdNotation(node, this.currentLevel + 1), this.currentLevel + 1);
this.onData(this.writer.dtdNotation(node, this.writerOptions, this.currentLevel + 1), this.currentLevel + 1);
return this;

@@ -307,7 +382,37 @@ };

XMLDocumentCB.prototype.openNode = function(node) {
var att, chunk, name, ref1;
if (!node.isOpen) {
if (!this.root && this.currentLevel === 0 && node instanceof XMLElement) {
if (!this.root && this.currentLevel === 0 && node.type === NodeType.Element) {
this.root = node;
}
this.onData(this.writer.openNode(node, this.currentLevel), this.currentLevel);
chunk = '';
if (node.type === NodeType.Element) {
this.writerOptions.state = WriterState.OpenTag;
chunk = this.writer.indent(node, this.writerOptions, this.currentLevel) + '<' + node.name;
ref1 = node.attribs;
for (name in ref1) {
if (!hasProp.call(ref1, name)) continue;
att = ref1[name];
chunk += this.writer.attribute(att, this.writerOptions, this.currentLevel);
}
chunk += (node.children ? '>' : '/>') + this.writer.endline(node, this.writerOptions, this.currentLevel);
this.writerOptions.state = WriterState.InsideTag;
} else {
this.writerOptions.state = WriterState.OpenTag;
chunk = this.writer.indent(node, this.writerOptions, this.currentLevel) + '<!DOCTYPE ' + node.rootNodeName;
if (node.pubID && node.sysID) {
chunk += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
} else if (node.sysID) {
chunk += ' SYSTEM "' + node.sysID + '"';
}
if (node.children) {
chunk += ' [';
this.writerOptions.state = WriterState.InsideTag;
} else {
this.writerOptions.state = WriterState.CloseTag;
chunk += '>';
}
chunk += this.writer.endline(node, this.writerOptions, this.currentLevel);
}
this.onData(chunk, this.currentLevel);
return node.isOpen = true;

@@ -318,4 +423,13 @@ }

XMLDocumentCB.prototype.closeNode = function(node) {
var chunk;
if (!node.isClosed) {
this.onData(this.writer.closeNode(node, this.currentLevel), this.currentLevel);
chunk = '';
this.writerOptions.state = WriterState.CloseTag;
if (node.type === NodeType.Element) {
chunk = this.writer.indent(node, this.writerOptions, this.currentLevel) + '</' + node.name + '>' + this.writer.endline(node, this.writerOptions, this.currentLevel);
} else {
chunk = this.writer.indent(node, this.writerOptions, this.currentLevel) + ']>' + this.writer.endline(node, this.writerOptions, this.currentLevel);
}
this.writerOptions.state = WriterState.None;
this.onData(chunk, this.currentLevel);
return node.isClosed = true;

@@ -404,3 +518,3 @@ }

XMLDocumentCB.prototype.att = function() {
if (this.currentNode && this.currentNode instanceof XMLDocType) {
if (this.currentNode && this.currentNode.type === NodeType.DocType) {
return this.attList.apply(this, arguments);

@@ -413,3 +527,3 @@ } else {

XMLDocumentCB.prototype.a = function() {
if (this.currentNode && this.currentNode instanceof XMLDocType) {
if (this.currentNode && this.currentNode.type === NodeType.DocType) {
return this.attList.apply(this, arguments);

@@ -416,0 +530,0 @@ } else {

// Generated by CoffeeScript 1.12.7
(function() {
var XMLDTDAttList, XMLNode,
var NodeType, XMLDTDAttList, XMLNode,
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; },

@@ -9,2 +9,4 @@ hasProp = {}.hasOwnProperty;

NodeType = require('./NodeType');
module.exports = XMLDTDAttList = (function(superClass) {

@@ -36,6 +38,9 @@ extend(XMLDTDAttList, superClass);

}
this.elementName = this.stringify.eleName(elementName);
this.attributeName = this.stringify.attName(attributeName);
this.elementName = this.stringify.name(elementName);
this.type = NodeType.AttributeDeclaration;
this.attributeName = this.stringify.name(attributeName);
this.attributeType = this.stringify.dtdAttType(attributeType);
this.defaultValue = this.stringify.dtdAttDefault(defaultValue);
if (defaultValue) {
this.defaultValue = this.stringify.dtdAttDefault(defaultValue);
}
this.defaultValueType = defaultValueType;

@@ -45,3 +50,3 @@ }

XMLDTDAttList.prototype.toString = function(options) {
return this.options.writer.set(options).dtdAttList(this);
return this.options.writer.dtdAttList(this, this.options.writer.filterOptions(options));
};

@@ -48,0 +53,0 @@

// Generated by CoffeeScript 1.12.7
(function() {
var XMLDTDElement, XMLNode,
var NodeType, XMLDTDElement, XMLNode,
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; },

@@ -9,2 +9,4 @@ hasProp = {}.hasOwnProperty;

NodeType = require('./NodeType');
module.exports = XMLDTDElement = (function(superClass) {

@@ -24,3 +26,4 @@ extend(XMLDTDElement, superClass);

}
this.name = this.stringify.eleName(name);
this.name = this.stringify.name(name);
this.type = NodeType.ElementDeclaration;
this.value = this.stringify.dtdElementValue(value);

@@ -30,3 +33,3 @@ }

XMLDTDElement.prototype.toString = function(options) {
return this.options.writer.set(options).dtdElement(this);
return this.options.writer.dtdElement(this, this.options.writer.filterOptions(options));
};

@@ -33,0 +36,0 @@

// Generated by CoffeeScript 1.12.7
(function() {
var XMLDTDEntity, XMLNode, isObject,
var NodeType, XMLDTDEntity, XMLNode, isObject,
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; },

@@ -11,2 +11,4 @@ hasProp = {}.hasOwnProperty;

NodeType = require('./NodeType');
module.exports = XMLDTDEntity = (function(superClass) {

@@ -24,5 +26,7 @@ extend(XMLDTDEntity, superClass);

this.pe = !!pe;
this.name = this.stringify.eleName(name);
this.name = this.stringify.name(name);
this.type = NodeType.EntityDeclaration;
if (!isObject(value)) {
this.value = this.stringify.dtdEntityValue(value);
this.internal = true;
} else {

@@ -35,2 +39,3 @@ if (!value.pubID && !value.sysID) {

}
this.internal = false;
if (value.pubID != null) {

@@ -51,4 +56,40 @@ this.pubID = this.stringify.dtdPubID(value.pubID);

Object.defineProperty(XMLDTDEntity.prototype, 'publicId', {
get: function() {
return this.pubID;
}
});
Object.defineProperty(XMLDTDEntity.prototype, 'systemId', {
get: function() {
return this.sysID;
}
});
Object.defineProperty(XMLDTDEntity.prototype, 'notationName', {
get: function() {
return this.nData || null;
}
});
Object.defineProperty(XMLDTDEntity.prototype, 'inputEncoding', {
get: function() {
return null;
}
});
Object.defineProperty(XMLDTDEntity.prototype, 'xmlEncoding', {
get: function() {
return null;
}
});
Object.defineProperty(XMLDTDEntity.prototype, 'xmlVersion', {
get: function() {
return null;
}
});
XMLDTDEntity.prototype.toString = function(options) {
return this.options.writer.set(options).dtdEntity(this);
return this.options.writer.dtdEntity(this, this.options.writer.filterOptions(options));
};

@@ -55,0 +96,0 @@

// Generated by CoffeeScript 1.12.7
(function() {
var XMLDTDNotation, XMLNode,
var NodeType, XMLDTDNotation, XMLNode,
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; },

@@ -9,2 +9,4 @@ hasProp = {}.hasOwnProperty;

NodeType = require('./NodeType');
module.exports = XMLDTDNotation = (function(superClass) {

@@ -21,3 +23,4 @@ extend(XMLDTDNotation, superClass);

}
this.name = this.stringify.eleName(name);
this.name = this.stringify.name(name);
this.type = NodeType.NotationDeclaration;
if (value.pubID != null) {

@@ -31,4 +34,16 @@ this.pubID = this.stringify.dtdPubID(value.pubID);

Object.defineProperty(XMLDTDNotation.prototype, 'publicId', {
get: function() {
return this.pubID;
}
});
Object.defineProperty(XMLDTDNotation.prototype, 'systemId', {
get: function() {
return this.sysID;
}
});
XMLDTDNotation.prototype.toString = function(options) {
return this.options.writer.set(options).dtdNotation(this);
return this.options.writer.dtdNotation(this, this.options.writer.filterOptions(options));
};

@@ -35,0 +50,0 @@

// Generated by CoffeeScript 1.12.7
(function() {
var XMLDummy, XMLNode,
var NodeType, XMLDummy, XMLNode,
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; },

@@ -9,2 +9,4 @@ hasProp = {}.hasOwnProperty;

NodeType = require('./NodeType');
module.exports = XMLDummy = (function(superClass) {

@@ -15,3 +17,3 @@ extend(XMLDummy, superClass);

XMLDummy.__super__.constructor.call(this, parent);
this.isDummy = true;
this.type = NodeType.Dummy;
}

@@ -18,0 +20,0 @@

// Generated by CoffeeScript 1.12.7
(function() {
var XMLAttribute, XMLElement, XMLNode, getValue, isFunction, isObject, ref,
var NodeType, XMLAttribute, XMLElement, XMLNamedNodeMap, XMLNode, getValue, isFunction, isObject, ref,
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; },

@@ -11,4 +11,8 @@ hasProp = {}.hasOwnProperty;

NodeType = require('./NodeType');
XMLAttribute = require('./XMLAttribute');
XMLNamedNodeMap = require('./XMLNamedNodeMap');
module.exports = XMLElement = (function(superClass) {

@@ -18,2 +22,3 @@ extend(XMLElement, superClass);

function XMLElement(parent, name, attributes) {
var child, j, len, ref1;
XMLElement.__super__.constructor.call(this, parent);

@@ -23,14 +28,77 @@ if (name == null) {

}
this.name = this.stringify.eleName(name);
this.attributes = {};
this.name = this.stringify.name(name);
this.type = NodeType.Element;
this.attribs = {};
this.schemaTypeInfo = null;
if (attributes != null) {
this.attribute(attributes);
}
if (parent.isDocument) {
if (parent.type === NodeType.Document) {
this.isRoot = true;
this.documentObject = parent;
parent.rootObject = this;
if (parent.children) {
ref1 = parent.children;
for (j = 0, len = ref1.length; j < len; j++) {
child = ref1[j];
if (child.type === NodeType.DocType) {
child.name = this.name;
break;
}
}
}
}
}
Object.defineProperty(XMLElement.prototype, 'tagName', {
get: function() {
return this.name;
}
});
Object.defineProperty(XMLElement.prototype, 'namespaceURI', {
get: function() {
return '';
}
});
Object.defineProperty(XMLElement.prototype, 'prefix', {
get: function() {
return '';
}
});
Object.defineProperty(XMLElement.prototype, 'localName', {
get: function() {
return this.name;
}
});
Object.defineProperty(XMLElement.prototype, 'id', {
get: function() {
throw new Error("This DOM method is not implemented." + this.debugInfo());
}
});
Object.defineProperty(XMLElement.prototype, 'className', {
get: function() {
throw new Error("This DOM method is not implemented." + this.debugInfo());
}
});
Object.defineProperty(XMLElement.prototype, 'classList', {
get: function() {
throw new Error("This DOM method is not implemented." + this.debugInfo());
}
});
Object.defineProperty(XMLElement.prototype, 'attributes', {
get: function() {
if (!this.attributeMap || !this.attributeMap.nodes) {
this.attributeMap = new XMLNamedNodeMap(this.attribs);
}
return this.attributeMap;
}
});
XMLElement.prototype.clone = function() {

@@ -42,8 +110,8 @@ var att, attName, clonedSelf, ref1;

}
clonedSelf.attributes = {};
ref1 = this.attributes;
clonedSelf.attribs = {};
ref1 = this.attribs;
for (attName in ref1) {
if (!hasProp.call(ref1, attName)) continue;
att = ref1[attName];
clonedSelf.attributes[attName] = att.clone();
clonedSelf.attribs[attName] = att.clone();
}

@@ -75,4 +143,6 @@ clonedSelf.children = [];

}
if (!this.options.skipNullAttributes || (value != null)) {
this.attributes[name] = new XMLAttribute(this, name, value);
if (this.options.keepNullAttributes && (value == null)) {
this.attribs[name] = new XMLAttribute(this, name, "");
} else if (value != null) {
this.attribs[name] = new XMLAttribute(this, name, value);
}

@@ -84,3 +154,3 @@ }

XMLElement.prototype.removeAttribute = function(name) {
var attName, i, len;
var attName, j, len;
if (name == null) {

@@ -91,8 +161,8 @@ throw new Error("Missing attribute name. " + this.debugInfo());

if (Array.isArray(name)) {
for (i = 0, len = name.length; i < len; i++) {
attName = name[i];
delete this.attributes[attName];
for (j = 0, len = name.length; j < len; j++) {
attName = name[j];
delete this.attribs[attName];
}
} else {
delete this.attributes[name];
delete this.attribs[name];
}

@@ -103,3 +173,3 @@ return this;

XMLElement.prototype.toString = function(options) {
return this.options.writer.set(options).element(this);
return this.options.writer.element(this, this.options.writer.filterOptions(options));
};

@@ -115,2 +185,119 @@

XMLElement.prototype.getAttribute = function(name) {
if (this.attribs.hasOwnProperty(name)) {
return this.attribs[name].value;
} else {
return null;
}
};
XMLElement.prototype.setAttribute = function(name, value) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLElement.prototype.getAttributeNode = function(name) {
if (this.attribs.hasOwnProperty(name)) {
return this.attribs[name];
} else {
return null;
}
};
XMLElement.prototype.setAttributeNode = function(newAttr) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLElement.prototype.removeAttributeNode = function(oldAttr) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLElement.prototype.getElementsByTagName = function(name) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLElement.prototype.getAttributeNS = function(namespaceURI, localName) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLElement.prototype.setAttributeNS = function(namespaceURI, qualifiedName, value) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLElement.prototype.removeAttributeNS = function(namespaceURI, localName) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLElement.prototype.getAttributeNodeNS = function(namespaceURI, localName) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLElement.prototype.setAttributeNodeNS = function(newAttr) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLElement.prototype.getElementsByTagNameNS = function(namespaceURI, localName) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLElement.prototype.hasAttribute = function(name) {
return this.attribs.hasOwnProperty(name);
};
XMLElement.prototype.hasAttributeNS = function(namespaceURI, localName) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLElement.prototype.setIdAttribute = function(name, isId) {
if (this.attribs.hasOwnProperty(name)) {
return this.attribs[name].isId;
} else {
return isId;
}
};
XMLElement.prototype.setIdAttributeNS = function(namespaceURI, localName, isId) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLElement.prototype.setIdAttributeNode = function(idAttr, isId) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLElement.prototype.getElementsByTagName = function(tagname) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLElement.prototype.getElementsByTagNameNS = function(namespaceURI, localName) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLElement.prototype.getElementsByClassName = function(classNames) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLElement.prototype.isEqualNode = function(node) {
var i, j, ref1;
if (!XMLElement.__super__.isEqualNode.apply(this, arguments).isEqualNode(node)) {
return false;
}
if (node.namespaceURI !== this.namespaceURI) {
return false;
}
if (node.prefix !== this.prefix) {
return false;
}
if (node.localName !== this.localName) {
return false;
}
if (node.attribs.length !== this.attribs.length) {
return false;
}
for (i = j = 0, ref1 = this.attribs.length - 1; 0 <= ref1 ? j <= ref1 : j >= ref1; i = 0 <= ref1 ? ++j : --j) {
if (!this.attribs[i].isEqualNode(node.attribs[i])) {
return false;
}
}
return true;
};
return XMLElement;

@@ -117,0 +304,0 @@

// Generated by CoffeeScript 1.12.7
(function() {
var XMLCData, XMLComment, XMLDeclaration, XMLDocType, XMLDummy, XMLElement, XMLNode, XMLProcessingInstruction, XMLRaw, XMLText, getValue, isEmpty, isFunction, isObject, ref,
var DocumentPosition, NodeType, XMLCData, XMLComment, XMLDeclaration, XMLDocType, XMLDummy, XMLElement, XMLNamedNodeMap, XMLNode, XMLNodeList, XMLProcessingInstruction, XMLRaw, XMLText, getValue, isEmpty, isFunction, isObject, ref1,
hasProp = {}.hasOwnProperty;
ref = require('./Utility'), isObject = ref.isObject, isFunction = ref.isFunction, isEmpty = ref.isEmpty, getValue = ref.getValue;
ref1 = require('./Utility'), isObject = ref1.isObject, isFunction = ref1.isFunction, isEmpty = ref1.isEmpty, getValue = ref1.getValue;

@@ -26,5 +26,13 @@ XMLElement = null;

NodeType = null;
XMLNodeList = null;
XMLNamedNodeMap = null;
DocumentPosition = null;
module.exports = XMLNode = (function() {
function XMLNode(parent) {
this.parent = parent;
function XMLNode(parent1) {
this.parent = parent1;
if (this.parent) {

@@ -34,3 +42,5 @@ this.options = this.parent.options;

}
this.value = null;
this.children = [];
this.baseURI = null;
if (!XMLElement) {

@@ -46,10 +56,119 @@ XMLElement = require('./XMLElement');

XMLDummy = require('./XMLDummy');
NodeType = require('./NodeType');
XMLNodeList = require('./XMLNodeList');
XMLNamedNodeMap = require('./XMLNamedNodeMap');
DocumentPosition = require('./DocumentPosition');
}
}
Object.defineProperty(XMLNode.prototype, 'nodeName', {
get: function() {
return this.name;
}
});
Object.defineProperty(XMLNode.prototype, 'nodeType', {
get: function() {
return this.type;
}
});
Object.defineProperty(XMLNode.prototype, 'nodeValue', {
get: function() {
return this.value;
}
});
Object.defineProperty(XMLNode.prototype, 'parentNode', {
get: function() {
return this.parent;
}
});
Object.defineProperty(XMLNode.prototype, 'childNodes', {
get: function() {
if (!this.childNodeList || !this.childNodeList.nodes) {
this.childNodeList = new XMLNodeList(this.children);
}
return this.childNodeList;
}
});
Object.defineProperty(XMLNode.prototype, 'firstChild', {
get: function() {
return this.children[0] || null;
}
});
Object.defineProperty(XMLNode.prototype, 'lastChild', {
get: function() {
return this.children[this.children.length - 1] || null;
}
});
Object.defineProperty(XMLNode.prototype, 'previousSibling', {
get: function() {
var i;
i = this.parent.children.indexOf(this);
return this.parent.children[i - 1] || null;
}
});
Object.defineProperty(XMLNode.prototype, 'nextSibling', {
get: function() {
var i;
i = this.parent.children.indexOf(this);
return this.parent.children[i + 1] || null;
}
});
Object.defineProperty(XMLNode.prototype, 'ownerDocument', {
get: function() {
return this.document() || null;
}
});
Object.defineProperty(XMLNode.prototype, 'textContent', {
get: function() {
var child, j, len, ref2, str;
if (this.nodeType === NodeType.Element || this.nodeType === NodeType.DocumentFragment) {
str = '';
ref2 = this.children;
for (j = 0, len = ref2.length; j < len; j++) {
child = ref2[j];
if (child.textContent) {
str += child.textContent;
}
}
return str;
} else {
return null;
}
},
set: function(value) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
}
});
XMLNode.prototype.setParent = function(parent) {
var child, j, len, ref2, results;
this.parent = parent;
if (parent) {
this.options = parent.options;
this.stringify = parent.stringify;
}
ref2 = this.children;
results = [];
for (j = 0, len = ref2.length; j < len; j++) {
child = ref2[j];
results.push(child.setParent(this));
}
return results;
};
XMLNode.prototype.element = function(name, attributes, text) {
var childNode, item, j, k, key, lastChild, len, len1, ref1, ref2, val;
var childNode, item, j, k, key, lastChild, len, len1, ref2, ref3, val;
lastChild = null;
if (attributes === null && (text == null)) {
ref1 = [{}, null], attributes = ref1[0], text = ref1[1];
ref2 = [{}, null], attributes = ref2[0], text = ref2[1];
}

@@ -61,3 +180,3 @@ if (attributes == null) {

if (!isObject(attributes)) {
ref2 = [attributes, text], text = ref2[0], attributes = ref2[1];
ref3 = [attributes, text], text = ref3[0], attributes = ref3[1];
}

@@ -81,7 +200,10 @@ if (name != null) {

}
if ((isObject(val)) && (isEmpty(val))) {
val = null;
}
if (!this.options.ignoreDecorators && this.stringify.convertAttKey && key.indexOf(this.stringify.convertAttKey) === 0) {
lastChild = this.attribute(key.substr(this.stringify.convertAttKey.length), val);
} else if (!this.options.separateArrayItems && Array.isArray(val) && isEmpty(val)) {
lastChild = this.dummy();
} else if (isObject(val) && isEmpty(val)) {
lastChild = this.element(key);
} else if (!this.options.keepNullNodes && (val == null)) {
lastChild = this.dummy();
} else if (!this.options.separateArrayItems && Array.isArray(val)) {

@@ -95,4 +217,8 @@ for (k = 0, len1 = val.length; k < len1; k++) {

} else if (isObject(val)) {
lastChild = this.element(key);
lastChild.element(val);
if (!this.options.ignoreDecorators && this.stringify.convertTextKey && key.indexOf(this.stringify.convertTextKey) === 0) {
lastChild = this.element(val);
} else {
lastChild = this.element(key);
lastChild.element(val);
}
} else {

@@ -102,3 +228,3 @@ lastChild = this.element(key, val);

}
} else if (this.options.skipNullNodes && text === null) {
} else if (!this.options.keepNullNodes && text === null) {
lastChild = this.dummy();

@@ -127,11 +253,26 @@ } else {

XMLNode.prototype.insertBefore = function(name, attributes, text) {
var child, i, removed;
if (this.isRoot) {
throw new Error("Cannot insert elements at root level. " + this.debugInfo(name));
var child, i, newChild, refChild, removed;
if (name != null ? name.type : void 0) {
newChild = name;
refChild = attributes;
newChild.setParent(this);
if (refChild) {
i = children.indexOf(refChild);
removed = children.splice(i);
children.push(newChild);
Array.prototype.push.apply(children, removed);
} else {
children.push(newChild);
}
return newChild;
} else {
if (this.isRoot) {
throw new Error("Cannot insert elements at root level. " + this.debugInfo(name));
}
i = this.parent.children.indexOf(this);
removed = this.parent.children.splice(i);
child = this.parent.element(name, attributes, text);
Array.prototype.push.apply(this.parent.children, removed);
return child;
}
i = this.parent.children.indexOf(this);
removed = this.parent.children.splice(i);
child = this.parent.element(name, attributes, text);
Array.prototype.push.apply(this.parent.children, removed);
return child;
};

@@ -152,3 +293,3 @@

XMLNode.prototype.remove = function() {
var i, ref1;
var i, ref2;
if (this.isRoot) {

@@ -158,3 +299,3 @@ throw new Error("Cannot remove the root element. " + this.debugInfo());

i = this.parent.children.indexOf(this);
[].splice.apply(this.parent.children, [i, i - i + 1].concat(ref1 = [])), ref1;
[].splice.apply(this.parent.children, [i, i - i + 1].concat(ref2 = [])), ref2;
return this.parent;

@@ -164,3 +305,3 @@ };

XMLNode.prototype.node = function(name, attributes, text) {
var child, ref1;
var child, ref2;
if (name != null) {

@@ -172,3 +313,3 @@ name = getValue(name);

if (!isObject(attributes)) {
ref1 = [attributes, text], text = ref1[0], attributes = ref1[1];
ref2 = [attributes, text], text = ref2[0], attributes = ref2[1];
}

@@ -185,2 +326,5 @@ child = new XMLElement(this, name, attributes);

var child;
if (isObject(value)) {
this.element(value);
}
child = new XMLText(this, value);

@@ -233,3 +377,2 @@ this.children.push(child);

child = new XMLDummy(this);
this.children.push(child);
return child;

@@ -289,3 +432,5 @@ };

xmldec = new XMLDeclaration(doc, version, encoding, standalone);
if (doc.children[0] instanceof XMLDeclaration) {
if (doc.children.length === 0) {
doc.children.unshift(xmldec);
} else if (doc.children[0].type === NodeType.Declaration) {
doc.children[0] = xmldec;

@@ -298,10 +443,10 @@ } else {

XMLNode.prototype.doctype = function(pubID, sysID) {
var child, doc, doctype, i, j, k, len, len1, ref1, ref2;
XMLNode.prototype.dtd = function(pubID, sysID) {
var child, doc, doctype, i, j, k, len, len1, ref2, ref3;
doc = this.document();
doctype = new XMLDocType(doc, pubID, sysID);
ref1 = doc.children;
for (i = j = 0, len = ref1.length; j < len; i = ++j) {
child = ref1[i];
if (child instanceof XMLDocType) {
ref2 = doc.children;
for (i = j = 0, len = ref2.length; j < len; i = ++j) {
child = ref2[i];
if (child.type === NodeType.DocType) {
doc.children[i] = doctype;

@@ -311,5 +456,5 @@ return doctype;

}
ref2 = doc.children;
for (i = k = 0, len1 = ref2.length; k < len1; i = ++k) {
child = ref2[i];
ref3 = doc.children;
for (i = k = 0, len1 = ref3.length; k < len1; i = ++k) {
child = ref3[i];
if (child.isRoot) {

@@ -335,3 +480,3 @@ doc.children.splice(i, 0, doctype);

while (node) {
if (node.isDocument) {
if (node.type === NodeType.Document) {
return node.rootObject;

@@ -350,3 +495,3 @@ } else if (node.isRoot) {

while (node) {
if (node.isDocument) {
if (node.type === NodeType.Document) {
return node;

@@ -366,5 +511,2 @@ } else {

i = this.parent.children.indexOf(this);
while (i > 0 && this.parent.children[i - 1].isDummy) {
i = i - 1;
}
if (i < 1) {

@@ -379,5 +521,2 @@ throw new Error("Already at the first node. " + this.debugInfo());

i = this.parent.children.indexOf(this);
while (i < this.parent.children.length - 1 && this.parent.children[i + 1].isDummy) {
i = i + 1;
}
if (i === -1 || i === this.parent.children.length - 1) {

@@ -399,9 +538,9 @@ throw new Error("Already at the last node. " + this.debugInfo());

XMLNode.prototype.debugInfo = function(name) {
var ref1, ref2;
var ref2, ref3;
name = name || this.name;
if ((name == null) && !((ref1 = this.parent) != null ? ref1.name : void 0)) {
if ((name == null) && !((ref2 = this.parent) != null ? ref2.name : void 0)) {
return "";
} else if (name == null) {
return "parent: <" + this.parent.name + ">";
} else if (!((ref2 = this.parent) != null ? ref2.name : void 0)) {
} else if (!((ref3 = this.parent) != null ? ref3.name : void 0)) {
return "node: <" + name + ">";

@@ -445,6 +584,2 @@ } else {

XMLNode.prototype.dtd = function(pubID, sysID) {
return this.doctype(pubID, sysID);
};
XMLNode.prototype.e = function(name, attributes, text) {

@@ -486,2 +621,185 @@ return this.element(name, attributes, text);

XMLNode.prototype.replaceChild = function(newChild, oldChild) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLNode.prototype.removeChild = function(oldChild) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLNode.prototype.appendChild = function(newChild) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLNode.prototype.hasChildNodes = function() {
return this.children.length !== 0;
};
XMLNode.prototype.cloneNode = function(deep) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLNode.prototype.normalize = function() {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLNode.prototype.isSupported = function(feature, version) {
return true;
};
XMLNode.prototype.hasAttributes = function() {
return this.attribs.length !== 0;
};
XMLNode.prototype.compareDocumentPosition = function(other) {
var ref, res;
ref = this;
if (ref === other) {
return 0;
} else if (this.document() !== other.document()) {
res = DocumentPosition.Disconnected | DocumentPosition.ImplementationSpecific;
if (Math.random() < 0.5) {
res |= DocumentPosition.Preceding;
} else {
res |= DocumentPosition.Following;
}
return res;
} else if (ref.isAncestor(other)) {
return DocumentPosition.Contains | DocumentPosition.Preceding;
} else if (ref.isDescendant(other)) {
return DocumentPosition.Contains | DocumentPosition.Following;
} else if (ref.isPreceding(other)) {
return DocumentPosition.Preceding;
} else {
return DocumentPosition.Following;
}
};
XMLNode.prototype.isSameNode = function(other) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLNode.prototype.lookupPrefix = function(namespaceURI) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLNode.prototype.isDefaultNamespace = function(namespaceURI) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLNode.prototype.lookupNamespaceURI = function(prefix) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLNode.prototype.isEqualNode = function(node) {
var i, j, ref2;
if (node.nodeType !== this.nodeType) {
return false;
}
if (node.children.length !== this.children.length) {
return false;
}
for (i = j = 0, ref2 = this.children.length - 1; 0 <= ref2 ? j <= ref2 : j >= ref2; i = 0 <= ref2 ? ++j : --j) {
if (!this.children[i].isEqualNode(node.children[i])) {
return false;
}
}
return true;
};
XMLNode.prototype.getFeature = function(feature, version) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLNode.prototype.setUserData = function(key, data, handler) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLNode.prototype.getUserData = function(key) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLNode.prototype.contains = function(other) {
if (!other) {
return false;
}
return other === this || this.isDescendant(other);
};
XMLNode.prototype.isDescendant = function(node) {
var child, isDescendantChild, j, len, ref2;
ref2 = this.children;
for (j = 0, len = ref2.length; j < len; j++) {
child = ref2[j];
if (node === child) {
return true;
}
isDescendantChild = child.isDescendant(node);
if (isDescendantChild) {
return true;
}
}
return false;
};
XMLNode.prototype.isAncestor = function(node) {
return node.isDescendant(this);
};
XMLNode.prototype.isPreceding = function(node) {
var nodePos, thisPos;
nodePos = this.treePosition(node);
thisPos = this.treePosition(this);
if (nodePos === -1 || thisPos === -1) {
return false;
} else {
return nodePos < thisPos;
}
};
XMLNode.prototype.isFollowing = function(node) {
var nodePos, thisPos;
nodePos = this.treePosition(node);
thisPos = this.treePosition(this);
if (nodePos === -1 || thisPos === -1) {
return false;
} else {
return nodePos > thisPos;
}
};
XMLNode.prototype.treePosition = function(node) {
var found, pos;
pos = 0;
found = false;
this.foreachTreeNode(this.document(), function(childNode) {
pos++;
if (!found && childNode === node) {
return found = true;
}
});
if (found) {
return pos;
} else {
return -1;
}
};
XMLNode.prototype.foreachTreeNode = function(node, func) {
var child, j, len, ref2, res;
node || (node = this.document());
ref2 = node.children;
for (j = 0, len = ref2.length; j < len; j++) {
child = ref2[j];
if (res = func(child)) {
return res;
} else {
res = this.foreachTreeNode(child, func);
if (res) {
return res;
}
}
}
};
return XMLNode;

@@ -488,0 +806,0 @@

// Generated by CoffeeScript 1.12.7
(function() {
var XMLNode, XMLProcessingInstruction,
var NodeType, XMLCharacterData, XMLProcessingInstruction,
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; },
hasProp = {}.hasOwnProperty;
XMLNode = require('./XMLNode');
NodeType = require('./NodeType');
XMLCharacterData = require('./XMLCharacterData');
module.exports = XMLProcessingInstruction = (function(superClass) {

@@ -17,3 +19,5 @@ extend(XMLProcessingInstruction, superClass);

}
this.type = NodeType.ProcessingInstruction;
this.target = this.stringify.insTarget(target);
this.name = this.target;
if (value) {

@@ -29,9 +33,19 @@ this.value = this.stringify.insValue(value);

XMLProcessingInstruction.prototype.toString = function(options) {
return this.options.writer.set(options).processingInstruction(this);
return this.options.writer.processingInstruction(this, this.options.writer.filterOptions(options));
};
XMLProcessingInstruction.prototype.isEqualNode = function(node) {
if (!XMLProcessingInstruction.__super__.isEqualNode.apply(this, arguments).isEqualNode(node)) {
return false;
}
if (node.target !== this.target) {
return false;
}
return true;
};
return XMLProcessingInstruction;
})(XMLNode);
})(XMLCharacterData);
}).call(this);
// Generated by CoffeeScript 1.12.7
(function() {
var XMLNode, XMLRaw,
var NodeType, XMLNode, XMLRaw,
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; },
hasProp = {}.hasOwnProperty;
NodeType = require('./NodeType');
XMLNode = require('./XMLNode');

@@ -17,2 +19,3 @@

}
this.type = NodeType.Raw;
this.value = this.stringify.raw(text);

@@ -26,3 +29,3 @@ }

XMLRaw.prototype.toString = function(options) {
return this.options.writer.set(options).raw(this);
return this.options.writer.raw(this, this.options.writer.filterOptions(options));
};

@@ -29,0 +32,0 @@

// Generated by CoffeeScript 1.12.7
(function() {
var XMLCData, XMLComment, XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDeclaration, XMLDocType, XMLDummy, XMLElement, XMLProcessingInstruction, XMLRaw, XMLStreamWriter, XMLText, XMLWriterBase,
var NodeType, WriterState, XMLStreamWriter, XMLWriterBase,
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; },
hasProp = {}.hasOwnProperty;
XMLDeclaration = require('./XMLDeclaration');
NodeType = require('./NodeType');
XMLDocType = require('./XMLDocType');
XMLWriterBase = require('./XMLWriterBase');
XMLCData = require('./XMLCData');
WriterState = require('./WriterState');
XMLComment = require('./XMLComment');
XMLElement = require('./XMLElement');
XMLRaw = require('./XMLRaw');
XMLText = require('./XMLText');
XMLProcessingInstruction = require('./XMLProcessingInstruction');
XMLDummy = require('./XMLDummy');
XMLDTDAttList = require('./XMLDTDAttList');
XMLDTDElement = require('./XMLDTDElement');
XMLDTDEntity = require('./XMLDTDEntity');
XMLDTDNotation = require('./XMLDTDNotation');
XMLWriterBase = require('./XMLWriterBase');
module.exports = XMLStreamWriter = (function(superClass) {

@@ -39,37 +17,27 @@ extend(XMLStreamWriter, superClass);

function XMLStreamWriter(stream, options) {
this.stream = stream;
XMLStreamWriter.__super__.constructor.call(this, options);
this.stream = stream;
}
XMLStreamWriter.prototype.document = function(doc) {
var child, i, j, len, len1, ref, ref1, results;
XMLStreamWriter.prototype.endline = function(node, options, level) {
if (node.isLastRootNode && options.state === WriterState.CloseTag) {
return '';
} else {
return XMLStreamWriter.__super__.endline.call(this, node, options, level);
}
};
XMLStreamWriter.prototype.document = function(doc, options) {
var child, i, j, k, len, len1, ref, ref1, results;
ref = doc.children;
for (i = 0, len = ref.length; i < len; i++) {
for (i = j = 0, len = ref.length; j < len; i = ++j) {
child = ref[i];
child.isLastRootNode = false;
child.isLastRootNode = i === doc.children.length - 1;
}
doc.children[doc.children.length - 1].isLastRootNode = true;
options = this.filterOptions(options);
ref1 = doc.children;
results = [];
for (j = 0, len1 = ref1.length; j < len1; j++) {
child = ref1[j];
if (child instanceof XMLDummy) {
continue;
}
switch (false) {
case !(child instanceof XMLDeclaration):
results.push(this.declaration(child));
break;
case !(child instanceof XMLDocType):
results.push(this.docType(child));
break;
case !(child instanceof XMLComment):
results.push(this.comment(child));
break;
case !(child instanceof XMLProcessingInstruction):
results.push(this.processingInstruction(child));
break;
default:
results.push(this.element(child));
}
for (k = 0, len1 = ref1.length; k < len1; k++) {
child = ref1[k];
results.push(this.writeChildNode(child, options, 0));
}

@@ -79,31 +47,24 @@ return results;

XMLStreamWriter.prototype.attribute = function(att) {
return this.stream.write(' ' + att.name + '="' + att.value + '"');
XMLStreamWriter.prototype.attribute = function(att, options, level) {
return this.stream.write(XMLStreamWriter.__super__.attribute.call(this, att, options, level));
};
XMLStreamWriter.prototype.cdata = function(node, level) {
return this.stream.write(this.space(level) + '<![CDATA[' + node.text + ']]>' + this.endline(node));
XMLStreamWriter.prototype.cdata = function(node, options, level) {
return this.stream.write(XMLStreamWriter.__super__.cdata.call(this, node, options, level));
};
XMLStreamWriter.prototype.comment = function(node, level) {
return this.stream.write(this.space(level) + '<!-- ' + node.text + ' -->' + this.endline(node));
XMLStreamWriter.prototype.comment = function(node, options, level) {
return this.stream.write(XMLStreamWriter.__super__.comment.call(this, node, options, level));
};
XMLStreamWriter.prototype.declaration = function(node, level) {
this.stream.write(this.space(level));
this.stream.write('<?xml version="' + node.version + '"');
if (node.encoding != null) {
this.stream.write(' encoding="' + node.encoding + '"');
}
if (node.standalone != null) {
this.stream.write(' standalone="' + node.standalone + '"');
}
this.stream.write(this.spacebeforeslash + '?>');
return this.stream.write(this.endline(node));
XMLStreamWriter.prototype.declaration = function(node, options, level) {
return this.stream.write(XMLStreamWriter.__super__.declaration.call(this, node, options, level));
};
XMLStreamWriter.prototype.docType = function(node, level) {
var child, i, len, ref;
XMLStreamWriter.prototype.docType = function(node, options, level) {
var child, j, len, ref;
level || (level = 0);
this.stream.write(this.space(level));
this.openNode(node, options, level);
options.state = WriterState.OpenTag;
this.stream.write(this.indent(node, options, level));
this.stream.write('<!DOCTYPE ' + node.root().name);

@@ -117,170 +78,98 @@ if (node.pubID && node.sysID) {

this.stream.write(' [');
this.stream.write(this.endline(node));
this.stream.write(this.endline(node, options, level));
options.state = WriterState.InsideTag;
ref = node.children;
for (i = 0, len = ref.length; i < len; i++) {
child = ref[i];
switch (false) {
case !(child instanceof XMLDTDAttList):
this.dtdAttList(child, level + 1);
break;
case !(child instanceof XMLDTDElement):
this.dtdElement(child, level + 1);
break;
case !(child instanceof XMLDTDEntity):
this.dtdEntity(child, level + 1);
break;
case !(child instanceof XMLDTDNotation):
this.dtdNotation(child, level + 1);
break;
case !(child instanceof XMLCData):
this.cdata(child, level + 1);
break;
case !(child instanceof XMLComment):
this.comment(child, level + 1);
break;
case !(child instanceof XMLProcessingInstruction):
this.processingInstruction(child, level + 1);
break;
default:
throw new Error("Unknown DTD node type: " + child.constructor.name);
}
for (j = 0, len = ref.length; j < len; j++) {
child = ref[j];
this.writeChildNode(child, options, level + 1);
}
options.state = WriterState.CloseTag;
this.stream.write(']');
}
this.stream.write(this.spacebeforeslash + '>');
return this.stream.write(this.endline(node));
options.state = WriterState.CloseTag;
this.stream.write(options.spaceBeforeSlash + '>');
this.stream.write(this.endline(node, options, level));
options.state = WriterState.None;
return this.closeNode(node, options, level);
};
XMLStreamWriter.prototype.element = function(node, level) {
var att, child, i, len, name, ref, ref1, space;
XMLStreamWriter.prototype.element = function(node, options, level) {
var att, child, childNodeCount, firstChildNode, j, len, name, prettySuppressed, ref, ref1;
level || (level = 0);
space = this.space(level);
this.stream.write(space + '<' + node.name);
ref = node.attributes;
this.openNode(node, options, level);
options.state = WriterState.OpenTag;
this.stream.write(this.indent(node, options, level) + '<' + node.name);
ref = node.attribs;
for (name in ref) {
if (!hasProp.call(ref, name)) continue;
att = ref[name];
this.attribute(att);
this.attribute(att, options, level);
}
if (node.children.length === 0 || node.children.every(function(e) {
return e.value === '';
childNodeCount = node.children.length;
firstChildNode = childNodeCount === 0 ? null : node.children[0];
if (childNodeCount === 0 || node.children.every(function(e) {
return (e.type === NodeType.Text || e.type === NodeType.Raw) && e.value === '';
})) {
if (this.allowEmpty) {
this.stream.write('></' + node.name + '>');
if (options.allowEmpty) {
this.stream.write('>');
options.state = WriterState.CloseTag;
this.stream.write('</' + node.name + '>');
} else {
this.stream.write(this.spacebeforeslash + '/>');
options.state = WriterState.CloseTag;
this.stream.write(options.spaceBeforeSlash + '/>');
}
} else if (this.pretty && node.children.length === 1 && (node.children[0].value != null)) {
} else if (options.pretty && childNodeCount === 1 && (firstChildNode.type === NodeType.Text || firstChildNode.type === NodeType.Raw) && (firstChildNode.value != null)) {
this.stream.write('>');
this.stream.write(node.children[0].value);
options.state = WriterState.InsideTag;
options.suppressPrettyCount++;
prettySuppressed = true;
this.writeChildNode(firstChildNode, options, level + 1);
options.suppressPrettyCount--;
prettySuppressed = false;
options.state = WriterState.CloseTag;
this.stream.write('</' + node.name + '>');
} else {
this.stream.write('>' + this.newline);
this.stream.write('>' + this.endline(node, options, level));
options.state = WriterState.InsideTag;
ref1 = node.children;
for (i = 0, len = ref1.length; i < len; i++) {
child = ref1[i];
switch (false) {
case !(child instanceof XMLCData):
this.cdata(child, level + 1);
break;
case !(child instanceof XMLComment):
this.comment(child, level + 1);
break;
case !(child instanceof XMLElement):
this.element(child, level + 1);
break;
case !(child instanceof XMLRaw):
this.raw(child, level + 1);
break;
case !(child instanceof XMLText):
this.text(child, level + 1);
break;
case !(child instanceof XMLProcessingInstruction):
this.processingInstruction(child, level + 1);
break;
case !(child instanceof XMLDummy):
'';
break;
default:
throw new Error("Unknown XML node type: " + child.constructor.name);
}
for (j = 0, len = ref1.length; j < len; j++) {
child = ref1[j];
this.writeChildNode(child, options, level + 1);
}
this.stream.write(space + '</' + node.name + '>');
options.state = WriterState.CloseTag;
this.stream.write(this.indent(node, options, level) + '</' + node.name + '>');
}
return this.stream.write(this.endline(node));
this.stream.write(this.endline(node, options, level));
options.state = WriterState.None;
return this.closeNode(node, options, level);
};
XMLStreamWriter.prototype.processingInstruction = function(node, level) {
this.stream.write(this.space(level) + '<?' + node.target);
if (node.value) {
this.stream.write(' ' + node.value);
}
return this.stream.write(this.spacebeforeslash + '?>' + this.endline(node));
XMLStreamWriter.prototype.processingInstruction = function(node, options, level) {
return this.stream.write(XMLStreamWriter.__super__.processingInstruction.call(this, node, options, level));
};
XMLStreamWriter.prototype.raw = function(node, level) {
return this.stream.write(this.space(level) + node.value + this.endline(node));
XMLStreamWriter.prototype.raw = function(node, options, level) {
return this.stream.write(XMLStreamWriter.__super__.raw.call(this, node, options, level));
};
XMLStreamWriter.prototype.text = function(node, level) {
return this.stream.write(this.space(level) + node.value + this.endline(node));
XMLStreamWriter.prototype.text = function(node, options, level) {
return this.stream.write(XMLStreamWriter.__super__.text.call(this, node, options, level));
};
XMLStreamWriter.prototype.dtdAttList = function(node, level) {
this.stream.write(this.space(level) + '<!ATTLIST ' + node.elementName + ' ' + node.attributeName + ' ' + node.attributeType);
if (node.defaultValueType !== '#DEFAULT') {
this.stream.write(' ' + node.defaultValueType);
}
if (node.defaultValue) {
this.stream.write(' "' + node.defaultValue + '"');
}
return this.stream.write(this.spacebeforeslash + '>' + this.endline(node));
XMLStreamWriter.prototype.dtdAttList = function(node, options, level) {
return this.stream.write(XMLStreamWriter.__super__.dtdAttList.call(this, node, options, level));
};
XMLStreamWriter.prototype.dtdElement = function(node, level) {
this.stream.write(this.space(level) + '<!ELEMENT ' + node.name + ' ' + node.value);
return this.stream.write(this.spacebeforeslash + '>' + this.endline(node));
XMLStreamWriter.prototype.dtdElement = function(node, options, level) {
return this.stream.write(XMLStreamWriter.__super__.dtdElement.call(this, node, options, level));
};
XMLStreamWriter.prototype.dtdEntity = function(node, level) {
this.stream.write(this.space(level) + '<!ENTITY');
if (node.pe) {
this.stream.write(' %');
}
this.stream.write(' ' + node.name);
if (node.value) {
this.stream.write(' "' + node.value + '"');
} else {
if (node.pubID && node.sysID) {
this.stream.write(' PUBLIC "' + node.pubID + '" "' + node.sysID + '"');
} else if (node.sysID) {
this.stream.write(' SYSTEM "' + node.sysID + '"');
}
if (node.nData) {
this.stream.write(' NDATA ' + node.nData);
}
}
return this.stream.write(this.spacebeforeslash + '>' + this.endline(node));
XMLStreamWriter.prototype.dtdEntity = function(node, options, level) {
return this.stream.write(XMLStreamWriter.__super__.dtdEntity.call(this, node, options, level));
};
XMLStreamWriter.prototype.dtdNotation = function(node, level) {
this.stream.write(this.space(level) + '<!NOTATION ' + node.name);
if (node.pubID && node.sysID) {
this.stream.write(' PUBLIC "' + node.pubID + '" "' + node.sysID + '"');
} else if (node.pubID) {
this.stream.write(' PUBLIC "' + node.pubID + '"');
} else if (node.sysID) {
this.stream.write(' SYSTEM "' + node.sysID + '"');
}
return this.stream.write(this.spacebeforeslash + '>' + this.endline(node));
XMLStreamWriter.prototype.dtdNotation = function(node, options, level) {
return this.stream.write(XMLStreamWriter.__super__.dtdNotation.call(this, node, options, level));
};
XMLStreamWriter.prototype.endline = function(node) {
if (!node.isLastRootNode) {
return this.newline;
} else {
return '';
}
};
return XMLStreamWriter;

@@ -287,0 +176,0 @@

@@ -9,6 +9,10 @@ // Generated by CoffeeScript 1.12.7

function XMLStringifier(options) {
this.assertLegalName = bind(this.assertLegalName, this);
this.assertLegalChar = bind(this.assertLegalChar, this);
var key, ref, value;
options || (options = {});
this.noDoubleEncoding = options.noDoubleEncoding;
this.options = options;
if (!this.options.version) {
this.options.version = '1.0';
}
ref = options.stringify || {};

@@ -22,13 +26,20 @@ for (key in ref) {

XMLStringifier.prototype.eleName = function(val) {
val = '' + val || '';
return this.assertLegalChar(val);
XMLStringifier.prototype.name = function(val) {
if (this.options.noValidation) {
return val;
}
return this.assertLegalName('' + val || '');
};
XMLStringifier.prototype.eleText = function(val) {
val = '' + val || '';
return this.assertLegalChar(this.elEscape(val));
XMLStringifier.prototype.text = function(val) {
if (this.options.noValidation) {
return val;
}
return this.assertLegalChar(this.textEscape('' + val || ''));
};
XMLStringifier.prototype.cdata = function(val) {
if (this.options.noValidation) {
return val;
}
val = '' + val || '';

@@ -40,2 +51,5 @@ val = val.replace(']]>', ']]]]><![CDATA[>');

XMLStringifier.prototype.comment = function(val) {
if (this.options.noValidation) {
return val;
}
val = '' + val || '';

@@ -49,19 +63,26 @@ if (val.match(/--/)) {

XMLStringifier.prototype.raw = function(val) {
if (this.options.noValidation) {
return val;
}
return '' + val || '';
};
XMLStringifier.prototype.attName = function(val) {
return val = '' + val || '';
};
XMLStringifier.prototype.attValue = function(val) {
val = '' + val || '';
return this.attEscape(val);
if (this.options.noValidation) {
return val;
}
return this.assertLegalChar(this.attEscape(val = '' + val || ''));
};
XMLStringifier.prototype.insTarget = function(val) {
return '' + val || '';
if (this.options.noValidation) {
return val;
}
return this.assertLegalChar('' + val || '');
};
XMLStringifier.prototype.insValue = function(val) {
if (this.options.noValidation) {
return val;
}
val = '' + val || '';

@@ -71,6 +92,9 @@ if (val.match(/\?>/)) {

}
return val;
return this.assertLegalChar(val);
};
XMLStringifier.prototype.xmlVersion = function(val) {
if (this.options.noValidation) {
return val;
}
val = '' + val || '';

@@ -84,2 +108,5 @@ if (!val.match(/1\.[0-9]+/)) {

XMLStringifier.prototype.xmlEncoding = function(val) {
if (this.options.noValidation) {
return val;
}
val = '' + val || '';

@@ -89,6 +116,9 @@ if (!val.match(/^[A-Za-z](?:[A-Za-z0-9._-])*$/)) {

}
return val;
return this.assertLegalChar(val);
};
XMLStringifier.prototype.xmlStandalone = function(val) {
if (this.options.noValidation) {
return val;
}
if (val) {

@@ -102,31 +132,48 @@ return "yes";

XMLStringifier.prototype.dtdPubID = function(val) {
return '' + val || '';
if (this.options.noValidation) {
return val;
}
return this.assertLegalChar('' + val || '');
};
XMLStringifier.prototype.dtdSysID = function(val) {
return '' + val || '';
if (this.options.noValidation) {
return val;
}
return this.assertLegalChar('' + val || '');
};
XMLStringifier.prototype.dtdElementValue = function(val) {
return '' + val || '';
if (this.options.noValidation) {
return val;
}
return this.assertLegalChar('' + val || '');
};
XMLStringifier.prototype.dtdAttType = function(val) {
return '' + val || '';
if (this.options.noValidation) {
return val;
}
return this.assertLegalChar('' + val || '');
};
XMLStringifier.prototype.dtdAttDefault = function(val) {
if (val != null) {
return '' + val || '';
} else {
if (this.options.noValidation) {
return val;
}
return this.assertLegalChar('' + val || '');
};
XMLStringifier.prototype.dtdEntityValue = function(val) {
return '' + val || '';
if (this.options.noValidation) {
return val;
}
return this.assertLegalChar('' + val || '');
};
XMLStringifier.prototype.dtdNData = function(val) {
return '' + val || '';
if (this.options.noValidation) {
return val;
}
return this.assertLegalChar('' + val || '');
};

@@ -147,13 +194,40 @@

XMLStringifier.prototype.assertLegalChar = function(str) {
var res;
res = str.match(/[\0\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/);
if (res) {
throw new Error("Invalid character in string: " + str + " at index " + res.index);
var regex, res;
if (this.options.noValidation) {
return str;
}
regex = '';
if (this.options.version === '1.0') {
regex = /[\0-\x08\x0B\f\x0E-\x1F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
if (res = str.match(regex)) {
throw new Error("Invalid character in string: " + str + " at index " + res.index);
}
} else if (this.options.version === '1.1') {
regex = /[\0\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
if (res = str.match(regex)) {
throw new Error("Invalid character in string: " + str + " at index " + res.index);
}
}
return str;
};
XMLStringifier.prototype.elEscape = function(str) {
XMLStringifier.prototype.assertLegalName = function(str) {
var regex;
if (this.options.noValidation) {
return str;
}
this.assertLegalChar(str);
regex = /^([:A-Z_a-z\xC0-\xD6\xD8-\xF6\xF8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]|[\uD800-\uDB7F][\uDC00-\uDFFF])([\x2D\.0-:A-Z_a-z\xB7\xC0-\xD6\xD8-\xF6\xF8-\u037D\u037F-\u1FFF\u200C\u200D\u203F\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]|[\uD800-\uDB7F][\uDC00-\uDFFF])*$/;
if (!str.match(regex)) {
throw new Error("Invalid character in name");
}
return str;
};
XMLStringifier.prototype.textEscape = function(str) {
var ampregex;
ampregex = this.noDoubleEncoding ? /(?!&\S+;)&/g : /&/g;
if (this.options.noValidation) {
return str;
}
ampregex = this.options.noDoubleEncoding ? /(?!&\S+;)&/g : /&/g;
return str.replace(ampregex, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\r/g, '&#xD;');

@@ -164,3 +238,6 @@ };

var ampregex;
ampregex = this.noDoubleEncoding ? /(?!&\S+;)&/g : /&/g;
if (this.options.noValidation) {
return str;
}
ampregex = this.options.noDoubleEncoding ? /(?!&\S+;)&/g : /&/g;
return str.replace(ampregex, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;').replace(/\t/g, '&#x9;').replace(/\n/g, '&#xA;').replace(/\r/g, '&#xD;');

@@ -167,0 +244,0 @@ };

// Generated by CoffeeScript 1.12.7
(function() {
var XMLCData, XMLComment, XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDeclaration, XMLDocType, XMLDummy, XMLElement, XMLProcessingInstruction, XMLRaw, XMLStringWriter, XMLText, XMLWriterBase,
var XMLStringWriter, XMLWriterBase,
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; },
hasProp = {}.hasOwnProperty;
XMLDeclaration = require('./XMLDeclaration');
XMLDocType = require('./XMLDocType');
XMLCData = require('./XMLCData');
XMLComment = require('./XMLComment');
XMLElement = require('./XMLElement');
XMLRaw = require('./XMLRaw');
XMLText = require('./XMLText');
XMLProcessingInstruction = require('./XMLProcessingInstruction');
XMLDummy = require('./XMLDummy');
XMLDTDAttList = require('./XMLDTDAttList');
XMLDTDElement = require('./XMLDTDElement');
XMLDTDEntity = require('./XMLDTDEntity');
XMLDTDNotation = require('./XMLDTDNotation');
XMLWriterBase = require('./XMLWriterBase');

@@ -42,5 +16,5 @@

XMLStringWriter.prototype.document = function(doc) {
XMLStringWriter.prototype.document = function(doc, options) {
var child, i, len, r, ref;
this.textispresent = false;
options = this.filterOptions(options);
r = '';

@@ -50,22 +24,6 @@ ref = doc.children;

child = ref[i];
if (child instanceof XMLDummy) {
continue;
}
r += (function() {
switch (false) {
case !(child instanceof XMLDeclaration):
return this.declaration(child);
case !(child instanceof XMLDocType):
return this.docType(child);
case !(child instanceof XMLComment):
return this.comment(child);
case !(child instanceof XMLProcessingInstruction):
return this.processingInstruction(child);
default:
return this.element(child, 0);
}
}).call(this);
r += this.writeChildNode(child, options, 0);
}
if (this.pretty && r.slice(-this.newline.length) === this.newline) {
r = r.slice(0, -this.newline.length);
if (options.pretty && r.slice(-options.newline.length) === options.newline) {
r = r.slice(0, -options.newline.length);
}

@@ -75,266 +33,2 @@ return r;

XMLStringWriter.prototype.attribute = function(att) {
return ' ' + att.name + '="' + att.value + '"';
};
XMLStringWriter.prototype.cdata = function(node, level) {
return this.space(level) + '<![CDATA[' + node.text + ']]>' + this.newline;
};
XMLStringWriter.prototype.comment = function(node, level) {
return this.space(level) + '<!-- ' + node.text + ' -->' + this.newline;
};
XMLStringWriter.prototype.declaration = function(node, level) {
var r;
r = this.space(level);
r += '<?xml version="' + node.version + '"';
if (node.encoding != null) {
r += ' encoding="' + node.encoding + '"';
}
if (node.standalone != null) {
r += ' standalone="' + node.standalone + '"';
}
r += this.spacebeforeslash + '?>';
r += this.newline;
return r;
};
XMLStringWriter.prototype.docType = function(node, level) {
var child, i, len, r, ref;
level || (level = 0);
r = this.space(level);
r += '<!DOCTYPE ' + node.root().name;
if (node.pubID && node.sysID) {
r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
} else if (node.sysID) {
r += ' SYSTEM "' + node.sysID + '"';
}
if (node.children.length > 0) {
r += ' [';
r += this.newline;
ref = node.children;
for (i = 0, len = ref.length; i < len; i++) {
child = ref[i];
r += (function() {
switch (false) {
case !(child instanceof XMLDTDAttList):
return this.dtdAttList(child, level + 1);
case !(child instanceof XMLDTDElement):
return this.dtdElement(child, level + 1);
case !(child instanceof XMLDTDEntity):
return this.dtdEntity(child, level + 1);
case !(child instanceof XMLDTDNotation):
return this.dtdNotation(child, level + 1);
case !(child instanceof XMLCData):
return this.cdata(child, level + 1);
case !(child instanceof XMLComment):
return this.comment(child, level + 1);
case !(child instanceof XMLProcessingInstruction):
return this.processingInstruction(child, level + 1);
default:
throw new Error("Unknown DTD node type: " + child.constructor.name);
}
}).call(this);
}
r += ']';
}
r += this.spacebeforeslash + '>';
r += this.newline;
return r;
};
XMLStringWriter.prototype.element = function(node, level) {
var att, child, i, j, len, len1, name, r, ref, ref1, ref2, space, textispresentwasset;
level || (level = 0);
textispresentwasset = false;
if (this.textispresent) {
this.newline = '';
this.pretty = false;
} else {
this.newline = this.newlinedefault;
this.pretty = this.prettydefault;
}
space = this.space(level);
r = '';
r += space + '<' + node.name;
ref = node.attributes;
for (name in ref) {
if (!hasProp.call(ref, name)) continue;
att = ref[name];
r += this.attribute(att);
}
if (node.children.length === 0 || node.children.every(function(e) {
return e.value === '';
})) {
if (this.allowEmpty) {
r += '></' + node.name + '>' + this.newline;
} else {
r += this.spacebeforeslash + '/>' + this.newline;
}
} else if (this.pretty && node.children.length === 1 && (node.children[0].value != null)) {
r += '>';
r += node.children[0].value;
r += '</' + node.name + '>' + this.newline;
} else {
if (this.dontprettytextnodes) {
ref1 = node.children;
for (i = 0, len = ref1.length; i < len; i++) {
child = ref1[i];
if (child.value != null) {
this.textispresent++;
textispresentwasset = true;
break;
}
}
}
if (this.textispresent) {
this.newline = '';
this.pretty = false;
space = this.space(level);
}
r += '>' + this.newline;
ref2 = node.children;
for (j = 0, len1 = ref2.length; j < len1; j++) {
child = ref2[j];
r += (function() {
switch (false) {
case !(child instanceof XMLCData):
return this.cdata(child, level + 1);
case !(child instanceof XMLComment):
return this.comment(child, level + 1);
case !(child instanceof XMLElement):
return this.element(child, level + 1);
case !(child instanceof XMLRaw):
return this.raw(child, level + 1);
case !(child instanceof XMLText):
return this.text(child, level + 1);
case !(child instanceof XMLProcessingInstruction):
return this.processingInstruction(child, level + 1);
case !(child instanceof XMLDummy):
return '';
default:
throw new Error("Unknown XML node type: " + child.constructor.name);
}
}).call(this);
}
if (textispresentwasset) {
this.textispresent--;
}
if (!this.textispresent) {
this.newline = this.newlinedefault;
this.pretty = this.prettydefault;
}
r += space + '</' + node.name + '>' + this.newline;
}
return r;
};
XMLStringWriter.prototype.processingInstruction = function(node, level) {
var r;
r = this.space(level) + '<?' + node.target;
if (node.value) {
r += ' ' + node.value;
}
r += this.spacebeforeslash + '?>' + this.newline;
return r;
};
XMLStringWriter.prototype.raw = function(node, level) {
return this.space(level) + node.value + this.newline;
};
XMLStringWriter.prototype.text = function(node, level) {
return this.space(level) + node.value + this.newline;
};
XMLStringWriter.prototype.dtdAttList = function(node, level) {
var r;
r = this.space(level) + '<!ATTLIST ' + node.elementName + ' ' + node.attributeName + ' ' + node.attributeType;
if (node.defaultValueType !== '#DEFAULT') {
r += ' ' + node.defaultValueType;
}
if (node.defaultValue) {
r += ' "' + node.defaultValue + '"';
}
r += this.spacebeforeslash + '>' + this.newline;
return r;
};
XMLStringWriter.prototype.dtdElement = function(node, level) {
return this.space(level) + '<!ELEMENT ' + node.name + ' ' + node.value + this.spacebeforeslash + '>' + this.newline;
};
XMLStringWriter.prototype.dtdEntity = function(node, level) {
var r;
r = this.space(level) + '<!ENTITY';
if (node.pe) {
r += ' %';
}
r += ' ' + node.name;
if (node.value) {
r += ' "' + node.value + '"';
} else {
if (node.pubID && node.sysID) {
r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
} else if (node.sysID) {
r += ' SYSTEM "' + node.sysID + '"';
}
if (node.nData) {
r += ' NDATA ' + node.nData;
}
}
r += this.spacebeforeslash + '>' + this.newline;
return r;
};
XMLStringWriter.prototype.dtdNotation = function(node, level) {
var r;
r = this.space(level) + '<!NOTATION ' + node.name;
if (node.pubID && node.sysID) {
r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
} else if (node.pubID) {
r += ' PUBLIC "' + node.pubID + '"';
} else if (node.sysID) {
r += ' SYSTEM "' + node.sysID + '"';
}
r += this.spacebeforeslash + '>' + this.newline;
return r;
};
XMLStringWriter.prototype.openNode = function(node, level) {
var att, name, r, ref;
level || (level = 0);
if (node instanceof XMLElement) {
r = this.space(level) + '<' + node.name;
ref = node.attributes;
for (name in ref) {
if (!hasProp.call(ref, name)) continue;
att = ref[name];
r += this.attribute(att);
}
r += (node.children ? '>' : '/>') + this.newline;
return r;
} else {
r = this.space(level) + '<!DOCTYPE ' + node.rootNodeName;
if (node.pubID && node.sysID) {
r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
} else if (node.sysID) {
r += ' SYSTEM "' + node.sysID + '"';
}
r += (node.children ? ' [' : '>') + this.newline;
return r;
}
};
XMLStringWriter.prototype.closeNode = function(node, level) {
level || (level = 0);
switch (false) {
case !(node instanceof XMLElement):
return this.space(level) + '</' + node.name + '>' + this.newline;
case !(node instanceof XMLDocType):
return this.space(level) + ']>' + this.newline;
}
};
return XMLStringWriter;

@@ -341,0 +35,0 @@

// Generated by CoffeeScript 1.12.7
(function() {
var XMLNode, XMLText,
var NodeType, XMLCharacterData, XMLText,
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; },
hasProp = {}.hasOwnProperty;
XMLNode = require('./XMLNode');
NodeType = require('./NodeType');
XMLCharacterData = require('./XMLCharacterData');
module.exports = XMLText = (function(superClass) {

@@ -17,5 +19,32 @@ extend(XMLText, superClass);

}
this.value = this.stringify.eleText(text);
this.name = "#text";
this.type = NodeType.Text;
this.value = this.stringify.text(text);
}
Object.defineProperty(XMLText.prototype, 'isElementContentWhitespace', {
get: function() {
throw new Error("This DOM method is not implemented." + this.debugInfo());
}
});
Object.defineProperty(XMLText.prototype, 'wholeText', {
get: function() {
var next, prev, str;
str = '';
prev = this.previousSibling;
while (prev) {
str = prev.data + str;
prev = prev.previousSibling;
}
str += this.data;
next = this.nextSibling;
while (next) {
str = str + next.data;
next = next.nextSibling;
}
return str;
}
});
XMLText.prototype.clone = function() {

@@ -26,9 +55,17 @@ return Object.create(this);

XMLText.prototype.toString = function(options) {
return this.options.writer.set(options).text(this);
return this.options.writer.text(this, this.options.writer.filterOptions(options));
};
XMLText.prototype.splitText = function(offset) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
XMLText.prototype.replaceWholeText = function(content) {
throw new Error("This DOM method is not implemented." + this.debugInfo());
};
return XMLText;
})(XMLNode);
})(XMLCharacterData);
}).call(this);
// Generated by CoffeeScript 1.12.7
(function() {
var XMLWriterBase,
var NodeType, WriterState, XMLCData, XMLComment, XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDeclaration, XMLDocType, XMLDummy, XMLElement, XMLProcessingInstruction, XMLRaw, XMLText, XMLWriterBase, assign,
hasProp = {}.hasOwnProperty;
assign = require('./Utility').assign;
NodeType = require('./NodeType');
XMLDeclaration = require('./XMLDeclaration');
XMLDocType = require('./XMLDocType');
XMLCData = require('./XMLCData');
XMLComment = require('./XMLComment');
XMLElement = require('./XMLElement');
XMLRaw = require('./XMLRaw');
XMLText = require('./XMLText');
XMLProcessingInstruction = require('./XMLProcessingInstruction');
XMLDummy = require('./XMLDummy');
XMLDTDAttList = require('./XMLDTDAttList');
XMLDTDElement = require('./XMLDTDElement');
XMLDTDEntity = require('./XMLDTDEntity');
XMLDTDNotation = require('./XMLDTDNotation');
WriterState = require('./WriterState');
module.exports = XMLWriterBase = (function() {
function XMLWriterBase(options) {
var key, ref, ref1, ref2, ref3, ref4, ref5, ref6, value;
var key, ref, value;
options || (options = {});
this.pretty = options.pretty || false;
this.allowEmpty = (ref = options.allowEmpty) != null ? ref : false;
if (this.pretty) {
this.indent = (ref1 = options.indent) != null ? ref1 : ' ';
this.newline = (ref2 = options.newline) != null ? ref2 : '\n';
this.offset = (ref3 = options.offset) != null ? ref3 : 0;
this.dontprettytextnodes = (ref4 = options.dontprettytextnodes) != null ? ref4 : 0;
} else {
this.indent = '';
this.newline = '';
this.offset = 0;
this.dontprettytextnodes = 0;
}
this.spacebeforeslash = (ref5 = options.spacebeforeslash) != null ? ref5 : '';
if (this.spacebeforeslash === true) {
this.spacebeforeslash = ' ';
}
this.newlinedefault = this.newline;
this.prettydefault = this.pretty;
ref6 = options.writer || {};
for (key in ref6) {
if (!hasProp.call(ref6, key)) continue;
value = ref6[key];
this.options = options;
ref = options.writer || {};
for (key in ref) {
if (!hasProp.call(ref, key)) continue;
value = ref[key];
this["_" + key] = this[key];
this[key] = value;

@@ -37,51 +52,374 @@ }

XMLWriterBase.prototype.set = function(options) {
var key, ref, value;
XMLWriterBase.prototype.filterOptions = function(options) {
var filteredOptions, ref, ref1, ref2, ref3, ref4, ref5, ref6;
options || (options = {});
if ("pretty" in options) {
this.pretty = options.pretty;
options = assign({}, this.options, options);
filteredOptions = {
writer: this
};
filteredOptions.pretty = options.pretty || false;
filteredOptions.allowEmpty = options.allowEmpty || false;
filteredOptions.indent = (ref = options.indent) != null ? ref : ' ';
filteredOptions.newline = (ref1 = options.newline) != null ? ref1 : '\n';
filteredOptions.offset = (ref2 = options.offset) != null ? ref2 : 0;
filteredOptions.dontPrettyTextNodes = (ref3 = (ref4 = options.dontPrettyTextNodes) != null ? ref4 : options.dontprettytextnodes) != null ? ref3 : 0;
filteredOptions.spaceBeforeSlash = (ref5 = (ref6 = options.spaceBeforeSlash) != null ? ref6 : options.spacebeforeslash) != null ? ref5 : '';
if (filteredOptions.spaceBeforeSlash === true) {
filteredOptions.spaceBeforeSlash = ' ';
}
if ("allowEmpty" in options) {
this.allowEmpty = options.allowEmpty;
filteredOptions.suppressPrettyCount = 0;
filteredOptions.user = {};
filteredOptions.state = WriterState.None;
return filteredOptions;
};
XMLWriterBase.prototype.indent = function(node, options, level) {
var indentLevel;
if (!options.pretty || options.suppressPrettyCount) {
return '';
} else if (options.pretty) {
indentLevel = (level || 0) + options.offset + 1;
if (indentLevel > 0) {
return new Array(indentLevel).join(options.indent);
}
}
if (this.pretty) {
this.indent = "indent" in options ? options.indent : ' ';
this.newline = "newline" in options ? options.newline : '\n';
this.offset = "offset" in options ? options.offset : 0;
this.dontprettytextnodes = "dontprettytextnodes" in options ? options.dontprettytextnodes : 0;
return '';
};
XMLWriterBase.prototype.endline = function(node, options, level) {
if (!options.pretty || options.suppressPrettyCount) {
return '';
} else {
this.indent = '';
this.newline = '';
this.offset = 0;
this.dontprettytextnodes = 0;
return options.newline;
}
this.spacebeforeslash = "spacebeforeslash" in options ? options.spacebeforeslash : '';
if (this.spacebeforeslash === true) {
this.spacebeforeslash = ' ';
};
XMLWriterBase.prototype.attribute = function(att, options, level) {
var r;
this.openAttribute(att, options, level);
r = ' ' + att.name + '="' + att.value + '"';
this.closeAttribute(att, options, level);
return r;
};
XMLWriterBase.prototype.cdata = function(node, options, level) {
var r;
this.openNode(node, options, level);
options.state = WriterState.OpenTag;
r = this.indent(node, options, level) + '<![CDATA[';
options.state = WriterState.InsideTag;
r += node.value;
options.state = WriterState.CloseTag;
r += ']]>' + this.endline(node, options, level);
options.state = WriterState.None;
this.closeNode(node, options, level);
return r;
};
XMLWriterBase.prototype.comment = function(node, options, level) {
var r;
this.openNode(node, options, level);
options.state = WriterState.OpenTag;
r = this.indent(node, options, level) + '<!-- ';
options.state = WriterState.InsideTag;
r += node.value;
options.state = WriterState.CloseTag;
r += ' -->' + this.endline(node, options, level);
options.state = WriterState.None;
this.closeNode(node, options, level);
return r;
};
XMLWriterBase.prototype.declaration = function(node, options, level) {
var r;
this.openNode(node, options, level);
options.state = WriterState.OpenTag;
r = this.indent(node, options, level) + '<?xml';
options.state = WriterState.InsideTag;
r += ' version="' + node.version + '"';
if (node.encoding != null) {
r += ' encoding="' + node.encoding + '"';
}
this.newlinedefault = this.newline;
this.prettydefault = this.pretty;
ref = options.writer || {};
for (key in ref) {
if (!hasProp.call(ref, key)) continue;
value = ref[key];
this[key] = value;
if (node.standalone != null) {
r += ' standalone="' + node.standalone + '"';
}
return this;
options.state = WriterState.CloseTag;
r += options.spaceBeforeSlash + '?>';
r += this.endline(node, options, level);
options.state = WriterState.None;
this.closeNode(node, options, level);
return r;
};
XMLWriterBase.prototype.space = function(level) {
var indent;
if (this.pretty) {
indent = (level || 0) + this.offset + 1;
if (indent > 0) {
return new Array(indent).join(this.indent);
XMLWriterBase.prototype.docType = function(node, options, level) {
var child, i, len, r, ref;
level || (level = 0);
this.openNode(node, options, level);
options.state = WriterState.OpenTag;
r = this.indent(node, options, level);
r += '<!DOCTYPE ' + node.root().name;
if (node.pubID && node.sysID) {
r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
} else if (node.sysID) {
r += ' SYSTEM "' + node.sysID + '"';
}
if (node.children.length > 0) {
r += ' [';
r += this.endline(node, options, level);
options.state = WriterState.InsideTag;
ref = node.children;
for (i = 0, len = ref.length; i < len; i++) {
child = ref[i];
r += this.writeChildNode(child, options, level + 1);
}
options.state = WriterState.CloseTag;
r += ']';
}
options.state = WriterState.CloseTag;
r += options.spaceBeforeSlash + '>';
r += this.endline(node, options, level);
options.state = WriterState.None;
this.closeNode(node, options, level);
return r;
};
XMLWriterBase.prototype.element = function(node, options, level) {
var att, child, childNodeCount, firstChildNode, i, j, len, len1, name, prettySuppressed, r, ref, ref1, ref2;
level || (level = 0);
prettySuppressed = false;
r = '';
this.openNode(node, options, level);
options.state = WriterState.OpenTag;
r += this.indent(node, options, level) + '<' + node.name;
ref = node.attribs;
for (name in ref) {
if (!hasProp.call(ref, name)) continue;
att = ref[name];
r += this.attribute(att, options, level);
}
childNodeCount = node.children.length;
firstChildNode = childNodeCount === 0 ? null : node.children[0];
if (childNodeCount === 0 || node.children.every(function(e) {
return (e.type === NodeType.Text || e.type === NodeType.Raw) && e.value === '';
})) {
if (options.allowEmpty) {
r += '>';
options.state = WriterState.CloseTag;
r += '</' + node.name + '>' + this.endline(node, options, level);
} else {
return '';
options.state = WriterState.CloseTag;
r += options.spaceBeforeSlash + '/>' + this.endline(node, options, level);
}
} else if (options.pretty && childNodeCount === 1 && (firstChildNode.type === NodeType.Text || firstChildNode.type === NodeType.Raw) && (firstChildNode.value != null)) {
r += '>';
options.state = WriterState.InsideTag;
options.suppressPrettyCount++;
prettySuppressed = true;
r += this.writeChildNode(firstChildNode, options, level + 1);
options.suppressPrettyCount--;
prettySuppressed = false;
options.state = WriterState.CloseTag;
r += '</' + node.name + '>' + this.endline(node, options, level);
} else {
return '';
if (options.dontPrettyTextNodes) {
ref1 = node.children;
for (i = 0, len = ref1.length; i < len; i++) {
child = ref1[i];
if ((child.type === NodeType.Text || child.type === NodeType.Raw) && (child.value != null)) {
options.suppressPrettyCount++;
prettySuppressed = true;
break;
}
}
}
r += '>' + this.endline(node, options, level);
options.state = WriterState.InsideTag;
ref2 = node.children;
for (j = 0, len1 = ref2.length; j < len1; j++) {
child = ref2[j];
r += this.writeChildNode(child, options, level + 1);
}
options.state = WriterState.CloseTag;
r += this.indent(node, options, level) + '</' + node.name + '>';
if (prettySuppressed) {
options.suppressPrettyCount--;
}
r += this.endline(node, options, level);
options.state = WriterState.None;
}
this.closeNode(node, options, level);
return r;
};
XMLWriterBase.prototype.writeChildNode = function(node, options, level) {
switch (node.type) {
case NodeType.CData:
return this.cdata(node, options, level);
case NodeType.Comment:
return this.comment(node, options, level);
case NodeType.Element:
return this.element(node, options, level);
case NodeType.Raw:
return this.raw(node, options, level);
case NodeType.Text:
return this.text(node, options, level);
case NodeType.ProcessingInstruction:
return this.processingInstruction(node, options, level);
case NodeType.Dummy:
return '';
case NodeType.Declaration:
return this.declaration(node, options, level);
case NodeType.DocType:
return this.docType(node, options, level);
case NodeType.AttributeDeclaration:
return this.dtdAttList(node, options, level);
case NodeType.ElementDeclaration:
return this.dtdElement(node, options, level);
case NodeType.EntityDeclaration:
return this.dtdEntity(node, options, level);
case NodeType.NotationDeclaration:
return this.dtdNotation(node, options, level);
default:
throw new Error("Unknown XML node type: " + node.constructor.name);
}
};
XMLWriterBase.prototype.processingInstruction = function(node, options, level) {
var r;
this.openNode(node, options, level);
options.state = WriterState.OpenTag;
r = this.indent(node, options, level) + '<?';
options.state = WriterState.InsideTag;
r += node.target;
if (node.value) {
r += ' ' + node.value;
}
options.state = WriterState.CloseTag;
r += options.spaceBeforeSlash + '?>';
r += this.endline(node, options, level);
options.state = WriterState.None;
this.closeNode(node, options, level);
return r;
};
XMLWriterBase.prototype.raw = function(node, options, level) {
var r;
this.openNode(node, options, level);
options.state = WriterState.OpenTag;
r = this.indent(node, options, level);
options.state = WriterState.InsideTag;
r += node.value;
options.state = WriterState.CloseTag;
r += this.endline(node, options, level);
options.state = WriterState.None;
this.closeNode(node, options, level);
return r;
};
XMLWriterBase.prototype.text = function(node, options, level) {
var r;
this.openNode(node, options, level);
options.state = WriterState.OpenTag;
r = this.indent(node, options, level);
options.state = WriterState.InsideTag;
r += node.value;
options.state = WriterState.CloseTag;
r += this.endline(node, options, level);
options.state = WriterState.None;
this.closeNode(node, options, level);
return r;
};
XMLWriterBase.prototype.dtdAttList = function(node, options, level) {
var r;
this.openNode(node, options, level);
options.state = WriterState.OpenTag;
r = this.indent(node, options, level) + '<!ATTLIST';
options.state = WriterState.InsideTag;
r += ' ' + node.elementName + ' ' + node.attributeName + ' ' + node.attributeType;
if (node.defaultValueType !== '#DEFAULT') {
r += ' ' + node.defaultValueType;
}
if (node.defaultValue) {
r += ' "' + node.defaultValue + '"';
}
options.state = WriterState.CloseTag;
r += options.spaceBeforeSlash + '>' + this.endline(node, options, level);
options.state = WriterState.None;
this.closeNode(node, options, level);
return r;
};
XMLWriterBase.prototype.dtdElement = function(node, options, level) {
var r;
this.openNode(node, options, level);
options.state = WriterState.OpenTag;
r = this.indent(node, options, level) + '<!ELEMENT';
options.state = WriterState.InsideTag;
r += ' ' + node.name + ' ' + node.value;
options.state = WriterState.CloseTag;
r += options.spaceBeforeSlash + '>' + this.endline(node, options, level);
options.state = WriterState.None;
this.closeNode(node, options, level);
return r;
};
XMLWriterBase.prototype.dtdEntity = function(node, options, level) {
var r;
this.openNode(node, options, level);
options.state = WriterState.OpenTag;
r = this.indent(node, options, level) + '<!ENTITY';
options.state = WriterState.InsideTag;
if (node.pe) {
r += ' %';
}
r += ' ' + node.name;
if (node.value) {
r += ' "' + node.value + '"';
} else {
if (node.pubID && node.sysID) {
r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
} else if (node.sysID) {
r += ' SYSTEM "' + node.sysID + '"';
}
if (node.nData) {
r += ' NDATA ' + node.nData;
}
}
options.state = WriterState.CloseTag;
r += options.spaceBeforeSlash + '>' + this.endline(node, options, level);
options.state = WriterState.None;
this.closeNode(node, options, level);
return r;
};
XMLWriterBase.prototype.dtdNotation = function(node, options, level) {
var r;
this.openNode(node, options, level);
options.state = WriterState.OpenTag;
r = this.indent(node, options, level) + '<!NOTATION';
options.state = WriterState.InsideTag;
r += ' ' + node.name;
if (node.pubID && node.sysID) {
r += ' PUBLIC "' + node.pubID + '" "' + node.sysID + '"';
} else if (node.pubID) {
r += ' PUBLIC "' + node.pubID + '"';
} else if (node.sysID) {
r += ' SYSTEM "' + node.sysID + '"';
}
options.state = WriterState.CloseTag;
r += options.spaceBeforeSlash + '>' + this.endline(node, options, level);
options.state = WriterState.None;
this.closeNode(node, options, level);
return r;
};
XMLWriterBase.prototype.openNode = function(node, options, level) {};
XMLWriterBase.prototype.closeNode = function(node, options, level) {};
XMLWriterBase.prototype.openAttribute = function(att, options, level) {};
XMLWriterBase.prototype.closeAttribute = function(att, options, level) {};
return XMLWriterBase;

@@ -88,0 +426,0 @@

{
"name": "xmlbuilder",
"version": "10.1.1",
"version": "11.0.0",
"keywords": [

@@ -30,3 +30,4 @@ "xml",

"istanbul": "*",
"coveralls": "*"
"coveralls": "*",
"xpath": "*"
},

@@ -33,0 +34,0 @@ "scripts": {

@@ -0,0 +0,0 @@ # xmlbuilder-js

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc