Skip to content

Commit ba5f35e

Browse files
committed
XML Parser v5
1 parent 364e327 commit ba5f35e

30 files changed

+2183
-17
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Note: If you find missing information about particular minor version, that version must have been changed without any functional change in this library.
22

3+
**4.3.5 / 2024-02-24**
4+
* code for v5 is added for experimental use
5+
36
**4.3.4 / 2024-01-10**
47
* fix: Don't escape entities in CDATA sections (#633) (By [wackbyte](https://github.com/wackbyte))
58

README.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
Validate XML, Parse XML to JS Object, or Build XML from JS Object without C/C++ based libraries and no callback.
1313

14-
<font size="6">I need a Career advice. I've posted the query on my <a href="github.com/amitguptagwl">profile</a>. Your support would be appreciable.</font>
14+
> XML Parser v5 is added for experimental use
15+
> https://solothought.com
1516
1617
Sponsor this project 👉
1718
<a href="https://github.com/sponsors/NaturalIntelligence">
@@ -91,6 +92,11 @@ If you want to be an anonymous user of this application and don't want to be hig
9192
* Supports parsing of PI (Processing Instruction) tags with XML declaration tags
9293
* And many more other features.
9394

95+
## v5
96+
I developed v5 in Apr 2023. And I didn't get the chance to complete all the features. I've ensured that new features don't impact performance. With v5, you have more control on parsing output. Check [docs](./docs/v5) for syntax help and basic understanding.
97+
98+
Please leave a comment in discussion forum for your suggestions and if you really need v5.
99+
94100
## How to use
95101

96102
To use as package dependency
@@ -174,19 +180,6 @@ Check lib folder for different browser bundles
174180

175181
[![](static/img/ni_ads_ads.gif)](https://github.com/NaturalIntelligence/ads/)
176182

177-
## Our other projects and research you must try
178-
179-
* **[BigBit standard](https://github.com/amitguptagwl/bigbit)** :
180-
* Single text encoding to replace UTF-8, UTF-16, UTF-32 and more with less memory.
181-
* Single Numeric datatype alternative of integer, float, double, long, decimal and more without precision loss.
182-
* **[Cytorus](https://github.com/NaturalIntelligence/cytorus)**: Be specific and flexible while running E2E tests.
183-
* Run tests only for a particular User Story
184-
* Run tests for a route or from a route
185-
* Customizable reporting
186-
* Central dashboard for better monitoring
187-
* Options to integrate E2E tests with Jira, Github etc using Central dashboard `Tian`.
188-
* **[Stubmatic](https://github.com/NaturalIntelligence/Stubmatic)** : Create fake webservices, DynamoDB or S3 servers, Manage fake/mock stub data, Or fake any HTTP(s) call.
189-
190183

191184
## Supporters
192185
### Contributors

docs/v5/1. Getting Started.md

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
2+
3+
Example
4+
5+
```js
6+
const options = {
7+
preserveOrder: true,
8+
removeNSPrefix: false, // remove NS from tag name or attribute name if true
9+
stopNodes: [], //nested tags will not be parsed even for errors
10+
htmlEntities: false,
11+
tags:{
12+
unpaired: [],
13+
nameFor:{
14+
cdata: false,
15+
comment: false,
16+
text: '#text'
17+
},
18+
separateTextProperty: false,
19+
//"join" only if preserveOrder: true
20+
valueParsers: ["trim","entities","join","boolean","number","currency","date"]
21+
},
22+
attributes: {
23+
ignore: false,
24+
booleanType:true,
25+
entities: true,
26+
//"groupBy": "att"
27+
},
28+
OutputBuilder: new JsObjOutputBuilder()
29+
};
30+
const parser = new XMLParser(options);
31+
let result = parser.parse(xmlData, true);
32+
```
33+
34+
- You can build your own Output Builder. FXP provides 3 builders
35+
- JsObjOutputBuilder
36+
- JsArrBuilder
37+
- JsMinArrBuilder
38+
- You can control the sequence of value parsing for a tag or attribute
39+
- You can pass a string or bytes array as input.
40+
41+
### Value Parser
42+
You can change the sequence of value parsers or remove one or provide your own parser to control the parsing.
43+
44+
### Output builders
45+
You can use provided output builds or your own output builder.
46+
47+
JsObjOutputBuilder
48+
```js
49+
{
50+
"soap:Envelope": {
51+
"@_xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/",
52+
"soap:Body": {
53+
"rpt:loadReportFileResponseElem": {
54+
"@_xmlns:s": "http://bus.x.com/common/support/v1",
55+
"@_xmlns:rpt": "http://bus.x.com/service/statement/v1",
56+
"s:code": 0,
57+
"s:responseTime": 2588,
58+
"s:responseDbTime": 1893,
59+
"s:requestId": "6b408fd09eb211e7a0807e34820340ec",
60+
"s:route": "172.16.x.x:9192",
61+
"rpt:result": {
62+
"rpt:file": "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap:Body>\n <rpt:loadReportFileResponseElem\n xmlns:s=\"http://bus.x.com/common/support/v1\"\n xmlns:rpt=\"http://bus.x.com/service/statement/v1\">\n <s:code>0</s:code>\n <s:responseTime>2588</s:responseTime>\n <s:responseDbTime>1893</s:responseDbTime>\n <s:requestId>6b408fd09eb211e7a0807e34820340ec</s:requestId>\n <s:route>172.16.x.x:9192</s:route>\n <rpt:result>\n <rpt:file></rpt:file>\n </rpt:result>\n </rpt:loadReportFileResponseElem>\n </soap:Body>\n</soap:Envelope>"
63+
}
64+
}
65+
}
66+
}
67+
}
68+
```
69+
70+
JsArrBuilder
71+
```js
72+
{
73+
"tagname": "soap:Envelope",
74+
"child": [
75+
{
76+
"tagname": "soap:Body",
77+
"child": [
78+
{
79+
"tagname": "rpt:loadReportFileResponseElem",
80+
"child": [
81+
{
82+
"tagname": "s:code",
83+
"child": [
84+
{
85+
"#text": 0
86+
}
87+
]
88+
},
89+
{
90+
"tagname": "s:responseTime",
91+
"child": [
92+
{
93+
"#text": 2588
94+
}
95+
]
96+
},
97+
{
98+
"tagname": "s:responseDbTime",
99+
"child": [
100+
{
101+
"#text": 1893
102+
}
103+
]
104+
},
105+
{
106+
"tagname": "s:requestId",
107+
"child": [
108+
{
109+
"#text": "6b408fd09eb211e7a0807e34820340ec"
110+
}
111+
]
112+
},
113+
{
114+
"tagname": "s:route",
115+
"child": [
116+
{
117+
"#text": "172.16.x.x:9192"
118+
}
119+
]
120+
},
121+
{
122+
"tagname": "rpt:result",
123+
"child": [
124+
{
125+
"tagname": "rpt:file",
126+
"child": [
127+
{
128+
"#text": "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap:Body>\n <rpt:loadReportFileResponseElem\n xmlns:s=\"http://bus.x.com/common/support/v1\"\n xmlns:rpt=\"http://bus.x.com/service/statement/v1\">\n <s:code>0</s:code>\n <s:responseTime>2588</s:responseTime>\n <s:responseDbTime>1893</s:responseDbTime>\n <s:requestId>6b408fd09eb211e7a0807e34820340ec</s:requestId>\n <s:route>172.16.x.x:9192</s:route>\n <rpt:result>\n <rpt:file></rpt:file>\n </rpt:result>\n </rpt:loadReportFileResponseElem>\n </soap:Body>\n</soap:Envelope>"
129+
}
130+
]
131+
}
132+
]
133+
}
134+
],
135+
":@": {
136+
"@_xmlns:s": "http://bus.x.com/common/support/v1",
137+
"@_xmlns:rpt": "http://bus.x.com/service/statement/v1"
138+
}
139+
}
140+
]
141+
}
142+
],
143+
":@": {
144+
"@_xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/"
145+
}
146+
}
147+
```
148+
149+
JsMinArrBuilder
150+
```js
151+
{
152+
"soap:Envelope": [
153+
{
154+
"soap:Body": [
155+
{
156+
"rpt:loadReportFileResponseElem": [
157+
{
158+
"s:code": [
159+
{
160+
"#text": 0
161+
}
162+
]
163+
},
164+
{
165+
"s:responseTime": [
166+
{
167+
"#text": 2588
168+
}
169+
]
170+
},
171+
{
172+
"s:responseDbTime": [
173+
{
174+
"#text": 1893
175+
}
176+
]
177+
},
178+
{
179+
"s:requestId": [
180+
{
181+
"#text": "6b408fd09eb211e7a0807e34820340ec"
182+
}
183+
]
184+
},
185+
{
186+
"s:route": [
187+
{
188+
"#text": "172.16.x.x:9192"
189+
}
190+
]
191+
},
192+
{
193+
"rpt:result": [
194+
{
195+
"rpt:file": [
196+
{
197+
"#text": "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap:Body>\n <rpt:loadReportFileResponseElem\n xmlns:s=\"http://bus.x.com/common/support/v1\"\n xmlns:rpt=\"http://bus.x.com/service/statement/v1\">\n <s:code>0</s:code>\n <s:responseTime>2588</s:responseTime>\n <s:responseDbTime>1893</s:responseDbTime>\n <s:requestId>6b408fd09eb211e7a0807e34820340ec</s:requestId>\n <s:route>172.16.x.x:9192</s:route>\n <rpt:result>\n <rpt:file></rpt:file>\n </rpt:result>\n </rpt:loadReportFileResponseElem>\n </soap:Body>\n</soap:Envelope>"
198+
}
199+
]
200+
}
201+
]
202+
}
203+
],
204+
":@": {
205+
"@_xmlns:s": "http://bus.x.com/common/support/v1",
206+
"@_xmlns:rpt": "http://bus.x.com/service/statement/v1"
207+
}
208+
}
209+
]
210+
}
211+
],
212+
":@": {
213+
"@_xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/"
214+
}
215+
}
216+
```
217+

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fast-xml-parser",
3-
"version": "4.3.4",
3+
"version": "4.3.5",
44
"description": "Validate XML, Parse XML, Build XML without C/C++ based libraries",
55
"main": "./src/fxp.js",
66
"scripts": {

spec/v5/test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const XMLParser = require("../../src/v5/XMLParser");
2+
const JsObjOutputBuilder = require("../../src/v5/OutputBuilders/JsObjBuilder");
3+
const JsArrBuilder = require("../../src/v5/OutputBuilders/JsArrBuilder");
4+
const JsMinArrBuilder = require("../../src/v5/OutputBuilders/JsMinArrBuilder");
5+
6+
const fs = require("fs");
7+
const path = require("path");
8+
const fileNamePath = path.join(__dirname, "../assets/ptest.xml");//with CDATA
9+
// const fileNamePath = path.join(__dirname, "../assets/ptest_with_prolog.xml");//with CDATA
10+
// const fileNamePath = path.join(__dirname, "../assets/sample.xml");//1.5k
11+
// const fileNamePath = path.join(__dirname, "../assets/midsize.xml");//13m
12+
// const fileNamePath = path.join(__dirname, "../assets/large.xml");//98m
13+
const xmlData = fs.readFileSync(fileNamePath).toString();
14+
15+
describe("XMLParser Entities", function() {
16+
17+
it("should parse", function() {
18+
19+
const options = {
20+
attributes: {
21+
ignore: false,
22+
booleanType:true
23+
},
24+
OutputBuilder: new JsMinArrBuilder()
25+
};
26+
const parser = new XMLParser(options);
27+
let result = parser.parse(xmlData);
28+
29+
console.log(JSON.stringify(result,null,4));
30+
// expect(result).toEqual(expected);
31+
});
32+
});

src/v5/CharsSymbol.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
modules.export = {
2+
"<" : "<", //tag start
3+
">" : ">", //tag end
4+
"/" : "/", //close tag
5+
"!" : "!", //comment or docttype
6+
"!--" : "!--", //comment
7+
"-->" : "-->", //comment end
8+
"?" : "?", //pi
9+
"?>" : "?>", //pi end
10+
"?xml" : "?xml", //pi end
11+
"![" : "![", //cdata
12+
"]]>" : "]]>", //cdata end
13+
"[" : "[",
14+
"-" : "-",
15+
"D" : "D",
16+
}

0 commit comments

Comments
 (0)