forked from NaturalIntelligence/fast-xml-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtry.mjs
More file actions
24 lines (18 loc) · 817 Bytes
/
Copy pathtry.mjs
File metadata and controls
24 lines (18 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import fs from "fs";
import path from "path";
// const fileNamePath = path.join(__dirname, "../spec/assets/test.json");//1.5k
// const jsonData = JSON.parse(fs.readFileSync(fileNamePath).toString());
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
// compatibility
const __dirname = dirname(fileURLToPath(import.meta.url));
// const xml2js = require("xml2js");
// const xml2jsBuilder = new xml2js.Builder();
// xml2jsBuilder.buildObject(jsonData);
import {XMLParser} from "../src/fxp.js";
const fileNamePath = path.join(__dirname, "../spec/assets/sample.xml");//1.5k
const xmlData = fs.readFileSync(fileNamePath).toString();
const fxpParserForOrderedJs = new XMLParser({preserveOrder: true});
console.log(
JSON.stringify(fxpParserForOrderedJs.parse(xmlData), null, 4)
);