xml2js 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec_status +5 -0
  3. data/CODE_OF_CONDUCT.md +74 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +41 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +44 -0
  8. data/Rakefile +6 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/lib/xml2js.rb +5 -0
  12. data/lib/xml2js/node_modules/sax/LICENSE +41 -0
  13. data/lib/xml2js/node_modules/sax/README.md +225 -0
  14. data/lib/xml2js/node_modules/sax/lib/sax.js +1565 -0
  15. data/lib/xml2js/node_modules/sax/package.json +61 -0
  16. data/lib/xml2js/node_modules/xml2js/LICENSE +19 -0
  17. data/lib/xml2js/node_modules/xml2js/README.md +406 -0
  18. data/lib/xml2js/node_modules/xml2js/lib/bom.js +12 -0
  19. data/lib/xml2js/node_modules/xml2js/lib/builder.js +127 -0
  20. data/lib/xml2js/node_modules/xml2js/lib/defaults.js +72 -0
  21. data/lib/xml2js/node_modules/xml2js/lib/parser.js +357 -0
  22. data/lib/xml2js/node_modules/xml2js/lib/processors.js +34 -0
  23. data/lib/xml2js/node_modules/xml2js/lib/xml2js.js +37 -0
  24. data/lib/xml2js/node_modules/xml2js/package.json +280 -0
  25. data/lib/xml2js/node_modules/xmlbuilder/.npmignore +5 -0
  26. data/lib/xml2js/node_modules/xmlbuilder/CHANGELOG.md +423 -0
  27. data/lib/xml2js/node_modules/xmlbuilder/LICENSE +21 -0
  28. data/lib/xml2js/node_modules/xmlbuilder/README.md +85 -0
  29. data/lib/xml2js/node_modules/xmlbuilder/lib/Utility.js +73 -0
  30. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLAttribute.js +31 -0
  31. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLCData.js +32 -0
  32. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLComment.js +32 -0
  33. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDTDAttList.js +50 -0
  34. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDTDElement.js +35 -0
  35. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDTDEntity.js +56 -0
  36. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDTDNotation.js +37 -0
  37. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDeclaration.js +40 -0
  38. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDocType.js +107 -0
  39. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDocument.js +48 -0
  40. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDocumentCB.js +402 -0
  41. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLElement.js +111 -0
  42. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLNode.js +432 -0
  43. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLProcessingInstruction.js +35 -0
  44. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLRaw.js +32 -0
  45. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLStreamWriter.js +279 -0
  46. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLStringWriter.js +334 -0
  47. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLStringifier.js +163 -0
  48. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLText.js +32 -0
  49. data/lib/xml2js/node_modules/xmlbuilder/lib/XMLWriterBase.js +90 -0
  50. data/lib/xml2js/node_modules/xmlbuilder/lib/index.js +53 -0
  51. data/lib/xml2js/node_modules/xmlbuilder/package.json +65 -0
  52. data/lib/xml2js/package-lock.json +25 -0
  53. data/lib/xml2js/parser.js +33 -0
  54. data/lib/xml2js/parser.rb +31 -0
  55. data/lib/xml2js/version.rb +3 -0
  56. data/xml2js.gemspec +30 -0
  57. metadata +154 -0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Ozgur Ozcitak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,85 @@
1
+ # xmlbuilder-js
2
+
3
+ An XML builder for [node.js](https://nodejs.org/) similar to
4
+ [java-xmlbuilder](https://github.com/jmurty/java-xmlbuilder).
5
+
6
+ [![License](http://img.shields.io/npm/l/xmlbuilder.svg?style=flat-square)](http://opensource.org/licenses/MIT)
7
+ [![NPM Version](http://img.shields.io/npm/v/xmlbuilder.svg?style=flat-square)](https://npmjs.com/package/xmlbuilder)
8
+ [![NPM Downloads](https://img.shields.io/npm/dm/xmlbuilder.svg?style=flat-square)](https://npmjs.com/package/xmlbuilder)
9
+
10
+ [![Build Status](http://img.shields.io/travis/oozcitak/xmlbuilder-js.svg?style=flat-square)](http://travis-ci.org/oozcitak/xmlbuilder-js)
11
+ [![Dev Dependency Status](http://img.shields.io/david/dev/oozcitak/xmlbuilder-js.svg?style=flat-square)](https://david-dm.org/oozcitak/xmlbuilder-js)
12
+ [![Code Coverage](https://img.shields.io/coveralls/oozcitak/xmlbuilder-js.svg?style=flat-square)](https://coveralls.io/github/oozcitak/xmlbuilder-js)
13
+
14
+ ### Installation:
15
+
16
+ ``` sh
17
+ npm install xmlbuilder
18
+ ```
19
+
20
+ ### Usage:
21
+
22
+ ``` js
23
+ var builder = require('xmlbuilder');
24
+ var xml = builder.create('root')
25
+ .ele('xmlbuilder')
26
+ .ele('repo', {'type': 'git'}, 'git://github.com/oozcitak/xmlbuilder-js.git')
27
+ .end({ pretty: true});
28
+
29
+ console.log(xml);
30
+ ```
31
+
32
+ will result in:
33
+
34
+ ``` xml
35
+ <?xml version="1.0"?>
36
+ <root>
37
+ <xmlbuilder>
38
+ <repo type="git">git://github.com/oozcitak/xmlbuilder-js.git</repo>
39
+ </xmlbuilder>
40
+ </root>
41
+ ```
42
+
43
+ It is also possible to convert objects into nodes:
44
+
45
+ ``` js
46
+ builder.create({
47
+ root: {
48
+ xmlbuilder: {
49
+ repo: {
50
+ '@type': 'git', // attributes start with @
51
+ '#text': 'git://github.com/oozcitak/xmlbuilder-js.git' // text node
52
+ }
53
+ }
54
+ }
55
+ });
56
+ ```
57
+
58
+ If you need to do some processing:
59
+
60
+ ``` js
61
+ var root = builder.create('squares');
62
+ root.com('f(x) = x^2');
63
+ for(var i = 1; i <= 5; i++)
64
+ {
65
+ var item = root.ele('data');
66
+ item.att('x', i);
67
+ item.att('y', i * i);
68
+ }
69
+ ```
70
+
71
+ This will result in:
72
+
73
+ ``` xml
74
+ <?xml version="1.0"?>
75
+ <squares>
76
+ <!-- f(x) = x^2 -->
77
+ <data x="1" y="1"/>
78
+ <data x="2" y="4"/>
79
+ <data x="3" y="9"/>
80
+ <data x="4" y="16"/>
81
+ <data x="5" y="25"/>
82
+ </squares>
83
+ ```
84
+
85
+ See the [wiki](https://github.com/oozcitak/xmlbuilder-js/wiki) for details and [examples](https://github.com/oozcitak/xmlbuilder-js/wiki/Examples) for more complex examples.
@@ -0,0 +1,73 @@
1
+ // Generated by CoffeeScript 1.12.7
2
+ (function() {
3
+ var assign, isArray, isEmpty, isFunction, isObject, isPlainObject,
4
+ slice = [].slice,
5
+ hasProp = {}.hasOwnProperty;
6
+
7
+ assign = function() {
8
+ var i, key, len, source, sources, target;
9
+ target = arguments[0], sources = 2 <= arguments.length ? slice.call(arguments, 1) : [];
10
+ if (isFunction(Object.assign)) {
11
+ Object.assign.apply(null, arguments);
12
+ } else {
13
+ for (i = 0, len = sources.length; i < len; i++) {
14
+ source = sources[i];
15
+ if (source != null) {
16
+ for (key in source) {
17
+ if (!hasProp.call(source, key)) continue;
18
+ target[key] = source[key];
19
+ }
20
+ }
21
+ }
22
+ }
23
+ return target;
24
+ };
25
+
26
+ isFunction = function(val) {
27
+ return !!val && Object.prototype.toString.call(val) === '[object Function]';
28
+ };
29
+
30
+ isObject = function(val) {
31
+ var ref;
32
+ return !!val && ((ref = typeof val) === 'function' || ref === 'object');
33
+ };
34
+
35
+ isArray = function(val) {
36
+ if (isFunction(Array.isArray)) {
37
+ return Array.isArray(val);
38
+ } else {
39
+ return Object.prototype.toString.call(val) === '[object Array]';
40
+ }
41
+ };
42
+
43
+ isEmpty = function(val) {
44
+ var key;
45
+ if (isArray(val)) {
46
+ return !val.length;
47
+ } else {
48
+ for (key in val) {
49
+ if (!hasProp.call(val, key)) continue;
50
+ return false;
51
+ }
52
+ return true;
53
+ }
54
+ };
55
+
56
+ isPlainObject = function(val) {
57
+ var ctor, proto;
58
+ return isObject(val) && (proto = Object.getPrototypeOf(val)) && (ctor = proto.constructor) && (typeof ctor === 'function') && (ctor instanceof ctor) && (Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object));
59
+ };
60
+
61
+ module.exports.assign = assign;
62
+
63
+ module.exports.isFunction = isFunction;
64
+
65
+ module.exports.isObject = isObject;
66
+
67
+ module.exports.isArray = isArray;
68
+
69
+ module.exports.isEmpty = isEmpty;
70
+
71
+ module.exports.isPlainObject = isPlainObject;
72
+
73
+ }).call(this);
@@ -0,0 +1,31 @@
1
+ // Generated by CoffeeScript 1.12.7
2
+ (function() {
3
+ var XMLAttribute;
4
+
5
+ module.exports = XMLAttribute = (function() {
6
+ function XMLAttribute(parent, name, value) {
7
+ this.options = parent.options;
8
+ this.stringify = parent.stringify;
9
+ if (name == null) {
10
+ throw new Error("Missing attribute name of element " + parent.name);
11
+ }
12
+ if (value == null) {
13
+ throw new Error("Missing attribute value for attribute " + name + " of element " + parent.name);
14
+ }
15
+ this.name = this.stringify.attName(name);
16
+ this.value = this.stringify.attValue(value);
17
+ }
18
+
19
+ XMLAttribute.prototype.clone = function() {
20
+ return Object.create(this);
21
+ };
22
+
23
+ XMLAttribute.prototype.toString = function(options) {
24
+ return this.options.writer.set(options).attribute(this);
25
+ };
26
+
27
+ return XMLAttribute;
28
+
29
+ })();
30
+
31
+ }).call(this);
@@ -0,0 +1,32 @@
1
+ // Generated by CoffeeScript 1.12.7
2
+ (function() {
3
+ var XMLCData, XMLNode,
4
+ extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
5
+ hasProp = {}.hasOwnProperty;
6
+
7
+ XMLNode = require('./XMLNode');
8
+
9
+ module.exports = XMLCData = (function(superClass) {
10
+ extend(XMLCData, superClass);
11
+
12
+ function XMLCData(parent, text) {
13
+ XMLCData.__super__.constructor.call(this, parent);
14
+ if (text == null) {
15
+ throw new Error("Missing CDATA text");
16
+ }
17
+ this.text = this.stringify.cdata(text);
18
+ }
19
+
20
+ XMLCData.prototype.clone = function() {
21
+ return Object.create(this);
22
+ };
23
+
24
+ XMLCData.prototype.toString = function(options) {
25
+ return this.options.writer.set(options).cdata(this);
26
+ };
27
+
28
+ return XMLCData;
29
+
30
+ })(XMLNode);
31
+
32
+ }).call(this);
@@ -0,0 +1,32 @@
1
+ // Generated by CoffeeScript 1.12.7
2
+ (function() {
3
+ var XMLComment, XMLNode,
4
+ extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
5
+ hasProp = {}.hasOwnProperty;
6
+
7
+ XMLNode = require('./XMLNode');
8
+
9
+ module.exports = XMLComment = (function(superClass) {
10
+ extend(XMLComment, superClass);
11
+
12
+ function XMLComment(parent, text) {
13
+ XMLComment.__super__.constructor.call(this, parent);
14
+ if (text == null) {
15
+ throw new Error("Missing comment text");
16
+ }
17
+ this.text = this.stringify.comment(text);
18
+ }
19
+
20
+ XMLComment.prototype.clone = function() {
21
+ return Object.create(this);
22
+ };
23
+
24
+ XMLComment.prototype.toString = function(options) {
25
+ return this.options.writer.set(options).comment(this);
26
+ };
27
+
28
+ return XMLComment;
29
+
30
+ })(XMLNode);
31
+
32
+ }).call(this);
@@ -0,0 +1,50 @@
1
+ // Generated by CoffeeScript 1.12.7
2
+ (function() {
3
+ var XMLDTDAttList, XMLNode,
4
+ extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
5
+ hasProp = {}.hasOwnProperty;
6
+
7
+ XMLNode = require('./XMLNode');
8
+
9
+ module.exports = XMLDTDAttList = (function(superClass) {
10
+ extend(XMLDTDAttList, superClass);
11
+
12
+ function XMLDTDAttList(parent, elementName, attributeName, attributeType, defaultValueType, defaultValue) {
13
+ XMLDTDAttList.__super__.constructor.call(this, parent);
14
+ if (elementName == null) {
15
+ throw new Error("Missing DTD element name");
16
+ }
17
+ if (attributeName == null) {
18
+ throw new Error("Missing DTD attribute name");
19
+ }
20
+ if (!attributeType) {
21
+ throw new Error("Missing DTD attribute type");
22
+ }
23
+ if (!defaultValueType) {
24
+ throw new Error("Missing DTD attribute default");
25
+ }
26
+ if (defaultValueType.indexOf('#') !== 0) {
27
+ defaultValueType = '#' + defaultValueType;
28
+ }
29
+ if (!defaultValueType.match(/^(#REQUIRED|#IMPLIED|#FIXED|#DEFAULT)$/)) {
30
+ throw new Error("Invalid default value type; expected: #REQUIRED, #IMPLIED, #FIXED or #DEFAULT");
31
+ }
32
+ if (defaultValue && !defaultValueType.match(/^(#FIXED|#DEFAULT)$/)) {
33
+ throw new Error("Default value only applies to #FIXED or #DEFAULT");
34
+ }
35
+ this.elementName = this.stringify.eleName(elementName);
36
+ this.attributeName = this.stringify.attName(attributeName);
37
+ this.attributeType = this.stringify.dtdAttType(attributeType);
38
+ this.defaultValue = this.stringify.dtdAttDefault(defaultValue);
39
+ this.defaultValueType = defaultValueType;
40
+ }
41
+
42
+ XMLDTDAttList.prototype.toString = function(options) {
43
+ return this.options.writer.set(options).dtdAttList(this);
44
+ };
45
+
46
+ return XMLDTDAttList;
47
+
48
+ })(XMLNode);
49
+
50
+ }).call(this);
@@ -0,0 +1,35 @@
1
+ // Generated by CoffeeScript 1.12.7
2
+ (function() {
3
+ var XMLDTDElement, XMLNode,
4
+ extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
5
+ hasProp = {}.hasOwnProperty;
6
+
7
+ XMLNode = require('./XMLNode');
8
+
9
+ module.exports = XMLDTDElement = (function(superClass) {
10
+ extend(XMLDTDElement, superClass);
11
+
12
+ function XMLDTDElement(parent, name, value) {
13
+ XMLDTDElement.__super__.constructor.call(this, parent);
14
+ if (name == null) {
15
+ throw new Error("Missing DTD element name");
16
+ }
17
+ if (!value) {
18
+ value = '(#PCDATA)';
19
+ }
20
+ if (Array.isArray(value)) {
21
+ value = '(' + value.join(',') + ')';
22
+ }
23
+ this.name = this.stringify.eleName(name);
24
+ this.value = this.stringify.dtdElementValue(value);
25
+ }
26
+
27
+ XMLDTDElement.prototype.toString = function(options) {
28
+ return this.options.writer.set(options).dtdElement(this);
29
+ };
30
+
31
+ return XMLDTDElement;
32
+
33
+ })(XMLNode);
34
+
35
+ }).call(this);
@@ -0,0 +1,56 @@
1
+ // Generated by CoffeeScript 1.12.7
2
+ (function() {
3
+ var XMLDTDEntity, XMLNode, isObject,
4
+ extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
5
+ hasProp = {}.hasOwnProperty;
6
+
7
+ isObject = require('./Utility').isObject;
8
+
9
+ XMLNode = require('./XMLNode');
10
+
11
+ module.exports = XMLDTDEntity = (function(superClass) {
12
+ extend(XMLDTDEntity, superClass);
13
+
14
+ function XMLDTDEntity(parent, pe, name, value) {
15
+ XMLDTDEntity.__super__.constructor.call(this, parent);
16
+ if (name == null) {
17
+ throw new Error("Missing entity name");
18
+ }
19
+ if (value == null) {
20
+ throw new Error("Missing entity value");
21
+ }
22
+ this.pe = !!pe;
23
+ this.name = this.stringify.eleName(name);
24
+ if (!isObject(value)) {
25
+ this.value = this.stringify.dtdEntityValue(value);
26
+ } else {
27
+ if (!value.pubID && !value.sysID) {
28
+ throw new Error("Public and/or system identifiers are required for an external entity");
29
+ }
30
+ if (value.pubID && !value.sysID) {
31
+ throw new Error("System identifier is required for a public external entity");
32
+ }
33
+ if (value.pubID != null) {
34
+ this.pubID = this.stringify.dtdPubID(value.pubID);
35
+ }
36
+ if (value.sysID != null) {
37
+ this.sysID = this.stringify.dtdSysID(value.sysID);
38
+ }
39
+ if (value.nData != null) {
40
+ this.nData = this.stringify.dtdNData(value.nData);
41
+ }
42
+ if (this.pe && this.nData) {
43
+ throw new Error("Notation declaration is not allowed in a parameter entity");
44
+ }
45
+ }
46
+ }
47
+
48
+ XMLDTDEntity.prototype.toString = function(options) {
49
+ return this.options.writer.set(options).dtdEntity(this);
50
+ };
51
+
52
+ return XMLDTDEntity;
53
+
54
+ })(XMLNode);
55
+
56
+ }).call(this);
@@ -0,0 +1,37 @@
1
+ // Generated by CoffeeScript 1.12.7
2
+ (function() {
3
+ var XMLDTDNotation, XMLNode,
4
+ extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
5
+ hasProp = {}.hasOwnProperty;
6
+
7
+ XMLNode = require('./XMLNode');
8
+
9
+ module.exports = XMLDTDNotation = (function(superClass) {
10
+ extend(XMLDTDNotation, superClass);
11
+
12
+ function XMLDTDNotation(parent, name, value) {
13
+ XMLDTDNotation.__super__.constructor.call(this, parent);
14
+ if (name == null) {
15
+ throw new Error("Missing notation name");
16
+ }
17
+ if (!value.pubID && !value.sysID) {
18
+ throw new Error("Public or system identifiers are required for an external entity");
19
+ }
20
+ this.name = this.stringify.eleName(name);
21
+ if (value.pubID != null) {
22
+ this.pubID = this.stringify.dtdPubID(value.pubID);
23
+ }
24
+ if (value.sysID != null) {
25
+ this.sysID = this.stringify.dtdSysID(value.sysID);
26
+ }
27
+ }
28
+
29
+ XMLDTDNotation.prototype.toString = function(options) {
30
+ return this.options.writer.set(options).dtdNotation(this);
31
+ };
32
+
33
+ return XMLDTDNotation;
34
+
35
+ })(XMLNode);
36
+
37
+ }).call(this);