Socket
Socket
Sign inDemoInstall

xmlbuilder

Package Overview
Dependencies
Maintainers
0
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 0.0.6 to 0.1.0

13

lib/XMLBuilder.js

@@ -19,6 +19,7 @@ (function() {

var att, child, root;
if (!name) {
if (!(name != null)) {
throw new Error("Root element needs a name");
}
this.children = [];
name = '' + name || '';
if ((xmldec != null) && !(xmldec.version != null)) {

@@ -31,3 +32,4 @@ throw new Error("Version number is required");

if (xmldec != null) {
if (!String(xmldec.version).match("^" + this.val.VersionNum + "$")) {
xmldec.version = '' + xmldec.version || '';
if (!xmldec.version.match(this.val.VersionNum)) {
throw new Error("Invalid version number: " + xmldec.version);

@@ -39,3 +41,4 @@ }

if (xmldec.encoding != null) {
if (!String(xmldec.encoding).match("^" + this.val.EncName + "$")) {
xmldec.encoding = '' + xmldec.encoding || '';
if (!xmldec.encoding.match(this.val.EncName)) {
throw new Error("Invalid encoding: " + xmldec.encoding);

@@ -45,3 +48,3 @@ }

}
if (xmldec.standalone) {
if (xmldec.standalone != null) {
att.standalone = xmldec.standalone ? "yes" : "no";

@@ -53,2 +56,3 @@ }

if (doctype != null) {
doctype.name = '' + doctype.name || '';
if (!String(doctype.name).match("^" + this.val.Name + "$")) {

@@ -61,2 +65,3 @@ throw new Error("Invalid document name: " + doctype.name);

if (doctype.ext != null) {
doctype.ext = '' + doctype.ext || '';
if (!String(doctype.ext).match("^" + this.val.ExternalID + "$")) {

@@ -63,0 +68,0 @@ throw new Error("Invalid external ID: " + doctype.ext);

(function() {
var XMLFragment;
var __hasProp = Object.prototype.hasOwnProperty;
XMLFragment = (function() {
function XMLFragment(parent, name, attributes, text) {
this.parent = parent;
this.name = name || '';
this.attributes = attributes || {};
this.value = text || '';
this.name = name;
this.attributes = attributes;
this.value = text;
this.children = [];
}
XMLFragment.prototype.element = function(name, attributes) {
var child;
if (this.value) {
throw new Error("Text nodes cannot have child nodes");
}
var child, key, val;
if (!(name != null)) {
throw new Error("Missing element name");
}
if (!String(name).match("^" + this.val.Name + "$")) {
name = '' + name || '';
attributes != null ? attributes : attributes = {};
for (key in attributes) {
if (!__hasProp.call(attributes, key)) continue;
val = attributes[key];
attributes[key] = this.escape(val);
}
if (!name.match("^" + this.val.Name + "$")) {
throw new Error("Invalid element name: " + name);

@@ -28,9 +33,8 @@ }

var child;
if (this.value) {
throw new Error("Text nodes cannot have child nodes");
}
if (!(value != null)) {
throw new Error("Missing element text");
}
if (!String(value).match("^" + this.val.CharData + "$") && !String(value).match(this.val.CDATA)) {
value = '' + value || '';
value = this.escape(value);
if (!value.match(this.val.CharData)) {
throw new Error("Invalid element text: " + value);

@@ -40,13 +44,25 @@ }

this.children.push(child);
return child;
return this;
};
XMLFragment.prototype.cdata = function(value) {
var child;
if (!(value != null)) {
throw new Error("Missing CDATA text");
}
value = '' + value || '';
if (!value.match(this.val.CDATA)) {
throw new Error("Invalid CDATA text: " + value);
}
child = new XMLFragment(this, '', {}, '<![CDATA[' + value + ']]>');
this.children.push(child);
return this;
};
XMLFragment.prototype.comment = function(value) {
var child;
if (this.value) {
throw new Error("Text nodes cannot have child nodes");
}
if (!(value != null)) {
throw new Error("Missing comment text");
}
if (!String(value).match("^" + this.val.CommentContent + "$")) {
value = '' + value || '';
value = this.escape(value);
if (!value.match("^" + this.val.CommentContent + "$")) {
throw new Error("Invalid comment text: " + value);

@@ -65,15 +81,15 @@ }

XMLFragment.prototype.attribute = function(name, value) {
if (this.value) {
throw new Error("Text nodes cannot have attributes");
}
if (!(name != null)) {
throw new Error("Missing attribute name");
}
if (!String(name).match("^" + this.val.Name + "$")) {
throw new Error("Invalid attribute name: " + name);
}
if (!(value != null)) {
throw new Error("Missing attribute value");
}
if (!String(value).match("^" + this.val.AttValue + "$")) {
name = '' + name || '';
value = '' + value || '';
value = this.escape(value);
if (!name.match("^" + this.val.Name + "$")) {
throw new Error("Invalid attribute name: " + name);
}
if (!value.match("^" + this.val.AttValue + "$")) {
throw new Error("Invalid attribute value: " + value);

@@ -98,3 +114,3 @@ }

} else {
r += this.value;
r += '' + this.value;
}

@@ -137,2 +153,5 @@ _ref = this.attributes;

};
XMLFragment.prototype.escape = function(str) {
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&apos;').replace(/"/g, '&quot;');
};
XMLFragment.prototype.ele = function(name, attributes) {

@@ -144,2 +163,5 @@ return this.element(name, attributes);

};
XMLFragment.prototype.dat = function(value) {
return this.cdata(value);
};
XMLFragment.prototype.att = function(name, value) {

@@ -157,2 +179,5 @@ return this.attribute(name, value);

};
XMLFragment.prototype.d = function(value) {
return this.cdata(value);
};
XMLFragment.prototype.a = function(name, value) {

@@ -172,7 +197,6 @@ return this.attribute(name, value);

XMLFragment.prototype.val.Char = "\u0009|\u000A|\u000D|[\u0020-\uD7FF]|[\uE000-\uFFFD]";
XMLFragment.prototype.val.NameStartChar = ":|[A-Z]|_|[a-z]|[\u00C0-\u00D6]|[\u00D8-\u00F6]|" + "[\u00F8-\u02FF]|[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|" + "[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD]";
XMLFragment.prototype.val.NameChar = ":|[A-Z]|_|[a-z]|[\u00C0-\u00D6]|[\u00D8-\u00F6]|[\u00F8-\u02FF]|" + "[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|[\u2C00-\u2FEF]|" + "[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD]" + "-|\.|[0-9]|\u00B7|[\u0300-\u036F]|[\u203F-\u2040]";
XMLFragment.prototype.val.NameStartChar = ":|[A-Z]|_|[a-z]|[\u00C0-\u00D6]|[\u00D8-\u00F6]|[\u00F8-\u02FF]|" + "[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|" + "[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD]";
XMLFragment.prototype.val.NameChar = XMLFragment.prototype.val.NameStartChar + '|' + "-|\.|[0-9]|\u00B7|[\u0300-\u036F]|[\u203F-\u2040]";
XMLFragment.prototype.val.CharRef = "&#[0-9]+;|&#x[0-9a-fA-F]+;";
XMLFragment.prototype.val.CharData = "(?![^<&]*]]>[^<&]*)[^<&]*";
XMLFragment.prototype.val.Name = XMLFragment.prototype.val.NameStartChar + '(?:' + XMLFragment.prototype.val.NameChar + ')*';
XMLFragment.prototype.val.Name = '(?:' + XMLFragment.prototype.val.NameStartChar + ')' + '(?:' + XMLFragment.prototype.val.NameChar + ')*';
XMLFragment.prototype.val.NMToken = '(?:' + XMLFragment.prototype.val.NameChar + ')+';

@@ -190,8 +214,9 @@ XMLFragment.prototype.val.EntityRef = '&' + XMLFragment.prototype.val.Name + ';';

XMLFragment.prototype.val.Comment = '<!--' + XMLFragment.prototype.val.CommentContent + '-->';
XMLFragment.prototype.val.VersionNum = '1\.[0-9]+';
XMLFragment.prototype.val.EncName = '[A-Za-z](?:[A-Za-z0-9\._]|-)*';
XMLFragment.prototype.val.ExternalID = '(?:' + 'SYSTEM' + XMLFragment.prototype.val.Space + XMLFragment.prototype.val.SystemLiteral + ')|';
'(?:' + 'PUBLIC' + XMLFragment.prototype.val.Space + XMLFragment.prototype.val.PubIDLateral + XMLFragment.prototype.val.Space + XMLFragment.prototype.val.SystemLiteral;
XMLFragment.prototype.val.CDATA = /^\<!\[CDATA\[.*?\]\]\>$/;
'(?:' + 'PUBLIC' + XMLFragment.prototype.val.Space + XMLFragment.prototype.val.PubIDLateral + XMLFragment.prototype.val.Space + XMLFragment.prototype.val.SystemLiteral + ')';
XMLFragment.prototype.val.CharData = /^(?![^<&]*]]>[^<&]*)[^<&]*$/;
XMLFragment.prototype.val.CDATA = /^(?:(?!]]>).)*$/;
XMLFragment.prototype.val.VersionNum = /^1\.[0-9]+$/;
XMLFragment.prototype.val.EncName = /^[A-Za-z](?:[A-Za-z0-9\._]|-)*$/;
module.exports = XMLFragment;
}).call(this);
{
"name" : "xmlbuilder",
"version": "0.0.6",
"version": "0.1.0",
"description": "An XML builder for node.js",

@@ -5,0 +5,0 @@ "author": "Ozgur Ozcitak <oozcitak@gmail.com>",

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