Skip to content

Commit fe7b06b

Browse files
committed
use the new xml to json lib
1 parent ba75543 commit fe7b06b

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

performance/src/utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import path, { dirname } from "path";
22
import { fileURLToPath } from "url";
33
import fs from "fs";
4-
import xmlToJson from "simple-xml-to-json";
4+
import { XMLParser } from "fast-xml-parser";
55

66
const __filename = fileURLToPath(import.meta.url);
77
const __dirname = dirname(__filename);
88

9+
const parser = new XMLParser();
10+
911
export function getFile(filePath: string): string {
1012
const fullPath = path.join(__dirname, "../data/", filePath);
1113

@@ -15,7 +17,7 @@ export function getFile(filePath: string): string {
1517
}
1618

1719
export function xmlToJsonAndWrite(xml: string, pathToSave: string): string {
18-
const json = xmlToJson.convertXML(xml);
20+
const json = parser.parse(xml, true);
1921

2022
console.log(JSON.stringify(json));
2123

@@ -29,7 +31,7 @@ function writeJson(path: string, content: string) {
2931
path + "/json/model.json",
3032
JSON.stringify(content, null, 2),
3133
{ flag: "w", encoding: "utf8" },
32-
(err) => {
34+
(err: Error) => {
3335
if (err) throw err;
3436
},
3537
);

0 commit comments

Comments
 (0)