Skip to content

Commit b77408b

Browse files
committed
code management
1 parent 2db2b60 commit b77408b

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

.vscode/launch.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
"${workspaceFolder}/spec/attr_spec.js"
1111
],
1212
"internalConsoleOptions": "openOnSessionStart"
13+
},{
14+
"type": "node",
15+
"request": "launch",
16+
"name": "Jasmine Tests current test file",
17+
"program": "${workspaceFolder}/node_modules/jasmine/bin/jasmine.js",
18+
"args": [
19+
"${file}"
20+
],
21+
"internalConsoleOptions": "openOnSessionStart"
1322
}
1423
]
1524

src/parser.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ exports.parse = function(xmlData, options, validationOption) {
1616
}
1717
}
1818
options = buildOptions(options, x2xmlnode.defaultOptions, x2xmlnode.props);
19-
return nodeToJson.convertToJson(xmlToNodeobj.getTraversalObj(xmlData, options), options);
19+
const traversableObj = xmlToNodeobj.getTraversalObj(xmlData, options)
20+
//print(traversableObj, " ");
21+
return nodeToJson.convertToJson(traversableObj, options);
2022
};
2123
exports.convertTonimn = require('../src/nimndata').convert2nimn;
2224
exports.getTraversalObj = xmlToNodeobj.getTraversalObj;
@@ -27,3 +29,39 @@ exports.j2xParser = require('./json2xml');
2729
exports.parseToNimn = function(xmlData, schema, options) {
2830
return exports.convertTonimn(exports.getTraversalObj(xmlData, options), schema, options);
2931
};
32+
33+
34+
function print(xmlNode, indentation){
35+
if(xmlNode){
36+
console.log(indentation + "{")
37+
console.log(indentation + " \"tagName\": \"" + xmlNode.tagname + "\", ");
38+
if(xmlNode.parent){
39+
console.log(indentation + " \"parent\": \"" + xmlNode.parent.tagname + "\", ");
40+
}
41+
console.log(indentation + " \"val\": \"" + xmlNode.val + "\", ");
42+
console.log(indentation + " \"attrs\": " + JSON.stringify(xmlNode.attrsMap,null,4) + ", ");
43+
44+
if(xmlNode.child){
45+
console.log(indentation + "\"child\": {")
46+
const indentation2 = indentation + indentation;
47+
Object.keys(xmlNode.child).forEach( key =>{
48+
const node = xmlNode.child[key];
49+
50+
if(Array.isArray(node)){
51+
console.log(indentation + "\""+key+"\" :[")
52+
node.forEach( (item,index) => {
53+
//console.log(indentation + " \""+index+"\" : [")
54+
print(item, indentation2);
55+
})
56+
console.log(indentation + "],")
57+
}else{
58+
console.log(indentation + " \""+key+"\" : {")
59+
print(node, indentation2);
60+
console.log(indentation + "},")
61+
}
62+
});
63+
console.log(indentation + "},")
64+
}
65+
console.log(indentation + "},")
66+
}
67+
}

0 commit comments

Comments
 (0)