Skip to content

Commit b3d583c

Browse files
committed
use common default options for XML parsing for consistency. And create parseToNimn method.
1 parent 7a66bbe commit b3d583c

File tree

4 files changed

+13
-41
lines changed

4 files changed

+13
-41
lines changed

lib/parser.js

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -566,24 +566,6 @@ var char = function (a){
566566
return String.fromCharCode(a);
567567
}
568568

569-
var defaultOptions = {
570-
attributeNamePrefix : "@_",
571-
attrNodeName: false,
572-
textNodeName : "#text",
573-
ignoreAttributes : true,
574-
ignoreNameSpace : false,
575-
allowBooleanAttributes : false, //a tag can have attributes without any value
576-
//ignoreRootElement : false,
577-
parseNodeValue : true,
578-
parseAttributeValue : false,
579-
arrayMode : false,
580-
trimValues: true, //Trim string values of tag and attributes
581-
decodeHTMLchar: false,
582-
cdataTagName: false,
583-
cdataPositionChar: "\\c"
584-
//decodeStrict: false,
585-
};
586-
587569
const chars = {
588570
nilChar : char(254),
589571
missingChar : char(200),
@@ -698,20 +680,23 @@ function hasData(jObj){
698680
}
699681
}
700682

683+
var defaultOptions = require("./x2j").defaultOptions;
701684
var convert2nimn = function(node,e_schema,options){
702685
options = Object.assign({},defaultOptions,options);
703686
return _e(node,e_schema,options)
704687
}
705688

706-
//exports.convert2nimn = _e;
707689
exports.convert2nimn = convert2nimn;
708-
},{}],4:[function(require,module,exports){
690+
},{"./x2j":7}],4:[function(require,module,exports){
709691
exports.parse = require("./x2j").parse;
710692
exports.convertTonimn = require("../src/nimndata").convert2nimn;
711693
exports.getTraversalObj = require("./x2j").getTraversalObj;
712694
exports.convertToJson = require("./x2j").convertToJson;
713695
exports.validate = require("./validator").validate;
714696
exports.j2xParser = require("./j2x");
697+
exports.parse2Nimn = function (xmlData,schema,options){
698+
return exports.convertTonimn(exports.getTraversalObj(xmlData,options), schema, options);
699+
};
715700

716701
},{"../src/nimndata":3,"./j2x":2,"./validator":6,"./x2j":7}],5:[function(require,module,exports){
717702
var getAllMatches = function(string, regex) {
@@ -1104,8 +1089,9 @@ var defaultOptions = {
11041089
//decodeStrict: false,
11051090
};
11061091

1092+
exports.defaultOptions = defaultOptions;
1093+
11071094
var getTraversalObj =function (xmlData,options){
1108-
//options = buildOptions(options);
11091095
options = Object.assign({},defaultOptions,options);
11101096
//xmlData = xmlData.replace(/\r?\n/g, " ");//make it single line
11111097
xmlData = xmlData.replace(/<!--[\s\S]*?-->/g, "");//Remove comments

src/nimndata.js

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,6 @@ var char = function (a){
22
return String.fromCharCode(a);
33
}
44

5-
var defaultOptions = {
6-
attributeNamePrefix : "@_",
7-
attrNodeName: false,
8-
textNodeName : "#text",
9-
ignoreAttributes : true,
10-
ignoreNameSpace : false,
11-
allowBooleanAttributes : false, //a tag can have attributes without any value
12-
//ignoreRootElement : false,
13-
parseNodeValue : true,
14-
parseAttributeValue : false,
15-
arrayMode : false,
16-
trimValues: true, //Trim string values of tag and attributes
17-
decodeHTMLchar: false,
18-
cdataTagName: false,
19-
cdataPositionChar: "\\c"
20-
//decodeStrict: false,
21-
};
22-
235
const chars = {
246
nilChar : char(254),
257
missingChar : char(200),
@@ -134,10 +116,10 @@ function hasData(jObj){
134116
}
135117
}
136118

119+
var defaultOptions = require("./x2j").defaultOptions;
137120
var convert2nimn = function(node,e_schema,options){
138121
options = Object.assign({},defaultOptions,options);
139122
return _e(node,e_schema,options)
140123
}
141124

142-
//exports.convert2nimn = _e;
143125
exports.convert2nimn = convert2nimn;

src/parser.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ exports.getTraversalObj = require("./x2j").getTraversalObj;
44
exports.convertToJson = require("./x2j").convertToJson;
55
exports.validate = require("./validator").validate;
66
exports.j2xParser = require("./j2x");
7+
exports.parseToNimn = function (xmlData,schema,options){
8+
return exports.convertTonimn(exports.getTraversalObj(xmlData,options), schema, options);
9+
};

src/x2j.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ var defaultOptions = {
2727
//decodeStrict: false,
2828
};
2929

30+
exports.defaultOptions = defaultOptions;
31+
3032
var getTraversalObj =function (xmlData,options){
31-
//options = buildOptions(options);
3233
options = Object.assign({},defaultOptions,options);
3334
//xmlData = xmlData.replace(/\r?\n/g, " ");//make it single line
3435
xmlData = xmlData.replace(/<!--[\s\S]*?-->/g, "");//Remove comments

0 commit comments

Comments
 (0)