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

xml-js

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml-js - npm Package Compare versions

Comparing version 0.9.6 to 0.9.7

9

lib/js2xml.js

@@ -144,3 +144,10 @@ var common = require('./common');

case options.commentKey: xml += writeIndentation(options, depth, firstLine) + writeComment(element, options); break;
default: xml += writeIndentation(options, depth, firstLine) + writeElementCompact(element[key], key, options, depth, hasContent(element[key], options, true));
default:
if (element[key] instanceof Array) {
element[key].forEach(function (el) {
xml += writeIndentation(options, depth, firstLine) + writeElementCompact(el, key, options, depth, hasContent(el, options, true));
});
} else {
xml += writeIndentation(options, depth, firstLine) + writeElementCompact(element[key], key, options, depth, hasContent(element[key], options, true));
}
}

@@ -147,0 +154,0 @@ firstLine = firstLine && !xml;

3

lib/xml2js.js

@@ -84,6 +84,5 @@ var sax = require('sax');

}
if (options.addParent && options.compact) {
if (options.addParent) {
currentElement[options.declarationKey][options.parentKey] = currentElement;
}
//console.error('result[options.declarationKey]', result[options.declarationKey]);
}

@@ -90,0 +89,0 @@

{
"name": "xml-js",
"version": "0.9.6",
"version": "0.9.7",
"description": "A convertor between XML text and Javascript object / JSON text.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -38,2 +38,5 @@ ![XML ⇔ JS/JSON](http://nashwaan.github.io/xml-js/images/logo.svg)

* **Minimal Dependencies**:
This library depends only on one external npm module.
* **Change Property Key Name**:

@@ -47,3 +50,3 @@ Usually output of XML attributes are stored in `@attr`, `_atrr`, `$attr`, `$`, or `whatever` in order to avoid conflicting with name of sub-elements.

* **Fast Code** (if required):
With little effort, the underlying [sax engine](https://www.npmjs.com/package/sax) (based on JavaScript) can be sustituted with [node-expat engine](https://github.com/astro/node-expat) (based on VC++).
With little effort, the underlying [sax engine](https://www.npmjs.com/package/sax) (based on JavaScript) can be substituted with [node-expat engine](https://github.com/astro/node-expat) (based on VC++).

@@ -50,0 +53,0 @@ * **Support Command Line**:

@@ -48,3 +48,8 @@ var cases = [

}, {
desc: 'should convert 2 elements',
desc: 'should convert 2 same elements',
xml: '<a/><a/>',
js1: {"a":[{},{}]},
js2: {"elements":[{"type":"element","name":"a"},{"type":"element","name":"a"}]},
}, {
desc: 'should convert 2 different elements',
xml: '<a/><b/>',

@@ -106,4 +111,8 @@ js1: {"a":{},"b":{}},

}
if (typeof obj[key] === 'object' && !(obj[key] instanceof Array)) {
if (options.compact && options.addParent && key !== '_attributes') {
if (options.addParent /*&& key.indexOf('declaration') === -1*/ && key.indexOf('attributes') === -1) {
if (obj[key] instanceof Array) {
obj[key].forEach(function (el) {
if (options.compact) {el._parent = obj;} else {el.parent = obj;}
});
} else if (typeof obj[key] === 'object' && !(obj[key] instanceof Array)) {
if (options.compact) {obj[key]._parent = obj;} else {obj[key].parent = obj;}

@@ -110,0 +119,0 @@ }

@@ -299,3 +299,3 @@ /*global describe,it,expect,beforeEach,afterEach*/

it('should output ', function () {
it('should output as expected json', function () {
expect(convert.xml2json(xml, {compact: true})).toEqual(JSON.stringify(json));

@@ -306,4 +306,44 @@ });

describe('case by Félix Dion Robidoux', function () {
var xml = '<ZohoCreator>' + '\n' +
' <applicationslist>' + '\n' +
' <application name="testapp">' + '\n' +
' <formlist>' + '\n' +
' <form name="Untitled_Form">' + '\n' +
' <add>' + '\n' +
' <field name="Subform_Single_Line">' + '\n' +
' <value>BEUHBALUGU</value>' + '\n' +
' </field>' + '\n' +
' </add>' + '\n' +
' </form>' + '\n' +
' <form name="Untitled_Form">' + '\n' +
' <add>' + '\n' +
' <field name="Subform_Single_Line">' + '\n' +
' <value>IF YOU CAN SEE THIS YOU DESERVE THE SUCC</value>' + '\n' +
' </field>' + '\n' +
' </add>' + '\n' +
' </form>' + '\n' +
' </formlist>' + '\n' +
' </application>' + '\n' +
' <application name="derp">' + '\n' +
' <formlist></formlist>' + '\n' +
' </application>' + '\n' +
' </applicationslist>' + '\n' +
'</ZohoCreator>';
/*xml = '<list>' + '\n' +
' <form name="A"></form>' + '\n' +
' <form name="B"></form>' + '\n' +
'</list>';*/
var json = convert.xml2json(xml, {compact: true, spaces: 4});
it('should output json and reverse it back to xml', function () {
expect(convert.json2xml(json, {compact: true, spaces: 4, fullTagEmptyElement: true})).toEqual(xml);
});
});
});
});
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