Skip to content

Commit

Permalink
Committed by npm script.
Browse files Browse the repository at this point in the history
  • Loading branch information
nashwaan committed May 24, 2017
1 parent 4c43cdb commit 0f98c84
Show file tree
Hide file tree
Showing 13 changed files with 759 additions and 289 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ node_modules/
test/browse-coverage/
test/fixtures/
.coveralls.yml
npm-debug.log
npm-debug.log
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ artwork/
test/
yarn.lock
*.log
*.yml
*.yml
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}\\test\\index.js",
"outFiles": [
"${workspaceRoot}/out/**/*.js"
]
}
]
}
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ The below options are applicable for both `xml2js()` and `xml2json()` functions.
| `addParent` | `false` | Whether to add `parent` property in each element object that points to parent object. |
| `alwaysArray` | `false` | Whether to always put sub element, even if it is one only, as an item inside an array. `<a><b/></a>` will be `a:[{b:[{}]}]` rather than `a:{b:{}}` (applicable for compact output only). |
| `alwaysChildren` | `false` | Whether to always generate `elements` property even when there are no actual sub elements. `<a></a>` will be `{"elements":[{"type":"element","name":"a","elements":[]}]}` rather than `{"elements":[{"type":"element","name":"a"}]}` (applicable for non-compact output). |
| `ignoreDeclaration` | `false` | Whether to ignore writing declaration property. That is, no `declaration` property will be generated. |
| `ignoreInstruction` | `false` | Whether to ignore writing processing instruction property. That is, no `instruction` property will be generated. |
| `ignoreAttributes` | `false` | Whether to ignore writing attributes of elements.That is, no `attributes` property will be generated. |
| `ignoreComment` | `false` | Whether to ignore writing comments of the elements. That is, no `comment` will be generated. |
| `ignoreCdata` | `false` | Whether to ignore writing CData of the elements. That is, no `cdata` will be generated. |
| `ignoreDoctype` | `false` | Whether to ignore writing Doctype of the elements. That is, no `doctype` will be generated. |
| `ignoreText` | `false` | Whether to ignore writing texts of the elements. That is, no `text` will be generated. |
| `ignoreDeclaration` | `false` | Whether to ignore parsing declaration property. That is, no `declaration` property will be generated. |
| `ignoreInstruction` | `false` | Whether to ignore parsing processing instruction property. That is, no `instruction` property will be generated. |
| `ignoreAttributes` | `false` | Whether to ignore parsing attributes of elements.That is, no `attributes` property will be generated. |
| `ignoreComment` | `false` | Whether to ignore parsing comments of the elements. That is, no `comment` will be generated. |
| `ignoreCdata` | `false` | Whether to ignore parsing CData of the elements. That is, no `cdata` will be generated. |
| `ignoreDoctype` | `false` | Whether to ignore parsing Doctype of the elements. That is, no `doctype` will be generated. |
| `ignoreText` | `false` | Whether to ignore parsing texts of the elements. That is, no `text` will be generated. |

The below option is applicable only for `xml2json()` function.

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./lib');
module.exports = require('./lib');
15 changes: 10 additions & 5 deletions lib/js2xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ function writeIndentation(options, depth, firstLine) {
return (!firstLine && options.spaces ? '\n' : '') + Array(depth + 1).join(options.spaces);
}

function writeAttributes(attributes) {
function writeAttributes(attributes, options) {
if (options.ignoreAttributes) {
return '';
}
var key, result = '';
for (key in attributes) {
if (attributes.hasOwnProperty(key)) {
Expand All @@ -46,10 +49,13 @@ function writeAttributes(attributes) {
}

function writeDeclaration(declaration, options) {
return '<?xml' + writeAttributes(declaration[options.attributesKey]) + '?>';
return options.ignoreDeclaration ? '' : '<?xml' + writeAttributes(declaration[options.attributesKey], options) + '?>';
}

function writeInstruction(instruction, options) {
if (options.ignoreInstruction) {
return '';
}
var key;
for (key in instruction) {
if (instruction.hasOwnProperty(key)) {
Expand Down Expand Up @@ -111,7 +117,7 @@ function writeElement(element, options, depth) {
var xml = '';
xml += '<' + element.name;
if (element[options.attributesKey]) {
xml += writeAttributes(element[options.attributesKey]);
xml += writeAttributes(element[options.attributesKey], options);
}
if (options.fullTagEmptyElement || (element[options.elementsKey] && element[options.elementsKey].length) || (element[options.attributesKey] && element[options.attributesKey]['xml:space'] === 'preserve')) {
xml += '>';
Expand Down Expand Up @@ -168,7 +174,6 @@ function hasContentCompact(element, options, anyContent) {
break; // skip to next key
case options.doctypeKey:
case options.commentKey:
case options.instructionKey:
return true;
default:
return true;
Expand All @@ -183,7 +188,7 @@ function writeElementCompact(element, name, options, depth, indent) {
if (name) {
xml += '<' + name;
if (element[options.attributesKey]) {
xml += writeAttributes(element[options.attributesKey]);
xml += writeAttributes(element[options.attributesKey], options);
}
if (options.fullTagEmptyElement || hasContentCompact(element, options, true) || element[options.attributesKey] && element[options.attributesKey]['xml:space'] === 'preserve') {
xml += '>';
Expand Down
3 changes: 3 additions & 0 deletions lib/xml2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ function addField(type, value, options) {
} else {
currentElement[options[type + 'Key']] = value;
}
// if (options.addParent && type === 'instruction') {
// value[options.parentKey] = currentElement;
// }
} else {
if (!currentElement[options.elementsKey]) {
currentElement[options.elementsKey] = [];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "git",
"url": "git+https://github.com/nashwaan/xml-js.git"
},
"author": "Yousuf Almarzooqi",
"author": "Yousuf Almarzooqi <ysf953@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/nashwaan/xml-js/issues"
Expand Down
Loading

0 comments on commit 0f98c84

Please sign in to comment.