Skip to content

Commit aa5d731

Browse files
committedApr 9, 2023
update package detail
1 parent 652a29e commit aa5d731

10 files changed

+70
-9
lines changed
 

‎CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
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.2.0 / 2023-04-09**
4+
* support `updateTag` parser property
5+
36
**4.1.4 / 2023-04-08**
47
* update typings to let user create XMLBuilder instance without options (#556) (By [Patrick](https://github.com/omggga))
58
* fix: IsArray option isn't parsing tags with 0 as value correctly #490 (#557) (By [Aleksandr Murashkin](https://github.com/p-kuen))
6-
* feature: support oneListGroup to group repeated children tags udder single group
9+
* feature: support `oneListGroup` to group repeated children tags udder single group
710

811
**4.1.3 / 2023-02-26**
912
* fix #546: Support complex entity value

‎docs/v4/2.XMLparseOptions.md

+25
Original file line numberDiff line numberDiff line change
@@ -905,4 +905,29 @@ Output
905905
}
906906
```
907907

908+
## updateTag
909+
910+
This property allow you to change tag name when you send different name, skip a tag from teh parsing result when you return false, or to change attributes.
911+
```js
912+
const xmlDataStr = `
913+
<rootNode>
914+
<a at="val">value</a>
915+
<b></b>
916+
</rootNode>`;
917+
918+
const options = {
919+
attributeNamePrefix: "",
920+
ignoreAttributes: false,
921+
updateTag(tagName, jPath, attrs){
922+
attrs["At"] = "Home";
923+
delete attrs["at"];
924+
925+
if(tagName === "a") return "A";
926+
else if(tagName === "b") return false;
927+
}
928+
};
929+
const parser = new XMLParser(options);
930+
const output = parser.parse(xmlDataStr);
931+
```
932+
908933
[> Next: XmlBuilder](./3.XMLBuilder.md)

‎lib/fxp.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/fxp.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/fxparser.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/fxparser.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

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

‎spec/temp.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"use strict";
2+
3+
const {XMLParser, XMLBuilder} = require("../src/fxp");
4+
5+
describe("unpaired and empty tags", function() {
6+
fit("bug test", function() {
7+
const xmlData = `<root>
8+
<a>1</a>
9+
<a></a>
10+
<a>2</a>
11+
<a></a>
12+
<a>3</a>
13+
<a></a>
14+
</root>`;
15+
const expected = {
16+
"root": {
17+
"a": [ 1,2,3]
18+
}
19+
};
20+
const options = {
21+
skipEmptyListItem: true
22+
};
23+
const parser = new XMLParser(options);
24+
// const parser = new XMLParser({ updateTag});
25+
let result = parser.parse(xmlData);
26+
27+
console.log(JSON.stringify(result,null,4));
28+
// expect(result).toEqual(expected);
29+
30+
});
31+
32+
});

‎src/xmlparser/OptionsBuilder.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ const defaultOptions = {
3636
transformAttributeName: false,
3737
updateTag: function(tagName, jPath, attrs){
3838
return tagName
39-
}
39+
},
40+
// skipEmptyListItem: false
4041
};
4142

4243
const buildOptions = function(options) {

0 commit comments

Comments
 (0)
Please sign in to comment.