fast-xml-parser
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
46042
160