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

fast-xml-parser

Package Overview
Dependencies
Maintainers
1
Versions
136
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-xml-parser - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

2

.vscode/launch.json

@@ -12,3 +12,3 @@ {

"name": "Launch Program",
"program": "${workspaceRoot}/index.js",
"program": "${workspaceRoot}/lib/parser.js",
"cwd": "${workspaceRoot}"

@@ -15,0 +15,0 @@ },

@@ -26,3 +26,4 @@ var getAllMatches = function(string, regex) {

var tagsRegx = new RegExp("<(\\/?[a-zA-Z0-9_:]+)([^>\\/]*)(\\/?)>([^<]+)?","g");
//var tagsRegx = new RegExp("<(\\/?[a-zA-Z0-9_:]+)([^>\\/]*)(\\/?)>([^<]+)?","g");
var tagsRegx = new RegExp("<(\\/?[\\w:-]+)([^>]*)>([^<]+)?","g");

@@ -53,32 +54,23 @@ var defaultOptions = {

var tags = getAllMatches(xmlData,tagsRegx);
var rootNode = new xmlNode(tags[0][1]);
var currentNode = rootNode;
var selfClosingTag = false;
for (var i = 1,j=0; i < tags.length -1 ; i++) {
var tag = tags[i][1];
var nexttag = tags[i+1][1];
var selfClosingTag = tags[i][3] === '/';
var xmlObj = new xmlNode('_xml');
var currentNode = xmlObj;
for (var i = 0; i < tags.length -1 ; i++) {
var tag = tags[i][1], attrsStr = tags[i][2], val = tags[i][3], nexttag = tags[i+1][1], attrs;
if(tag.indexOf("/") === 0){//ending tag
currentNode = currentNode.parent;
continue;
}
var selfClosingTag = attrsStr.charAt(attrsStr.length-1) === '/';
var childNode = new xmlNode(tag,currentNode);
if(selfClosingTag){
var childNode = new xmlNode(tag,currentNode);
var attrs = buildAttributesArr(tags[i][2],options.ignoreTextNodeAttr,options.attrPrefix);
attrs = buildAttributesArr(attrsStr,options.ignoreTextNodeAttr,options.attrPrefix);
childNode.val = attrs || "";
currentNode.addChild(childNode);
}else if( ("/" + tag) === nexttag || selfClosingTag){ //Text node
var val =tags[i][4];
if(val){
if(isNaN(val)){
val = "" + val ;
}else{
if(val.indexOf(".") !== -1){
val = Number.parseFloat(val);
}else{
val = Number.parseInt(val);
}
}
}else{
val = "";
}
var childNode = new xmlNode(tag,currentNode);
var attrs = buildAttributesArr(tags[i][2],options.ignoreTextNodeAttr,options.attrPrefix);
}else if( ("/" + tag) === nexttag){ //Text node
attrs = buildAttributesArr(attrsStr,options.ignoreTextNodeAttr,options.attrPrefix);
val = parseValue(val);
if(attrs){

@@ -92,27 +84,33 @@ attrs[options.textNodeName] = val;

i++;
}else if(tag.indexOf("/") === 0){//ending tag
currentNode = currentNode.parent;
continue;
}else{//starting tag
var cNode = new xmlNode(tag,currentNode);
var attrs = buildAttributesArr(tags[i][2],options.ignoreNonTextNodeAttr,options.attrPrefix);
attrs = buildAttributesArr(attrsStr,options.ignoreNonTextNodeAttr,options.attrPrefix);
if(attrs){
for (var property in attrs) {
if (attrs.hasOwnProperty(property)) {
cNode.addChild(new xmlNode(property,cNode,attrs[property]));
}
for (var prop in attrs) {
attrs.hasOwnProperty(prop) && childNode.addChild(new xmlNode(prop,childNode,attrs[prop]));
}
}
currentNode.addChild(cNode);
currentNode = cNode;
currentNode.addChild(childNode);
currentNode = childNode;
}
}
//include root node as well
var xmlObj = new xmlNode('_xml');
rootNode.param = xmlObj;
xmlObj.addChild(rootNode);
return convertToJson(xmlObj);
};
function parseValue(val){
if(val){
if(isNaN(val)){
val = "" + val ;
}else{
if(val.indexOf(".") !== -1){
val = Number.parseFloat(val);
}else{
val = Number.parseInt(val,10);
}
}
}else{
val = "";
}
return val;
}
var attrsRegx = new RegExp("(\\S+)=.([^'\"]+)","g");

@@ -158,2 +156,2 @@ function buildAttributesArr(attrStr,ignore,prefix){

exports.parse = xml2json;
exports.parse = xml2json;
{
"name": "fast-xml-parser",
"version": "2.0.0",
"version": "2.1.0",
"description": "Parse XML to JS/JSON very fast without C/C++ based libraries",

@@ -5,0 +5,0 @@ "main": "./lib/parser.js",

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