Skip to content

Commit

Permalink
update package detail
Browse files Browse the repository at this point in the history
  • Loading branch information
amitguptagwl committed Apr 9, 2023
1 parent 652a29e commit aa5d731
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 9 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
Note: If you find missing information about particular minor version, that version must have been changed without any functional change in this library.

**4.2.0 / 2023-04-09**
* support `updateTag` parser property

**4.1.4 / 2023-04-08**
* update typings to let user create XMLBuilder instance without options (#556) (By [Patrick](https://github.com/omggga))
* fix: IsArray option isn't parsing tags with 0 as value correctly #490 (#557) (By [Aleksandr Murashkin](https://github.com/p-kuen))
* feature: support oneListGroup to group repeated children tags udder single group
* feature: support `oneListGroup` to group repeated children tags udder single group

**4.1.3 / 2023-02-26**
* fix #546: Support complex entity value
Expand Down
25 changes: 25 additions & 0 deletions docs/v4/2.XMLparseOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -905,4 +905,29 @@ Output
}
```

## updateTag

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.
```js
const xmlDataStr = `
<rootNode>
<a at="val">value</a>
<b></b>
</rootNode>`;

const options = {
attributeNamePrefix: "",
ignoreAttributes: false,
updateTag(tagName, jPath, attrs){
attrs["At"] = "Home";
delete attrs["at"];

if(tagName === "a") return "A";
else if(tagName === "b") return false;
}
};
const parser = new XMLParser(options);
const output = parser.parse(xmlDataStr);
```

[> Next: XmlBuilder](./3.XMLBuilder.md)
2 changes: 1 addition & 1 deletion lib/fxp.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/fxp.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/fxparser.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/fxparser.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fast-xml-parser",
"version": "4.1.4",
"version": "4.2.0",
"description": "Validate XML, Parse XML, Build XML without C/C++ based libraries",
"main": "./src/fxp.js",
"scripts": {
Expand Down
32 changes: 32 additions & 0 deletions spec/temp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use strict";

const {XMLParser, XMLBuilder} = require("../src/fxp");

describe("unpaired and empty tags", function() {
fit("bug test", function() {
const xmlData = `<root>
<a>1</a>
<a></a>
<a>2</a>
<a></a>
<a>3</a>
<a></a>
</root>`;
const expected = {
"root": {
"a": [ 1,2,3]
}
};
const options = {
skipEmptyListItem: true
};
const parser = new XMLParser(options);
// const parser = new XMLParser({ updateTag});
let result = parser.parse(xmlData);

console.log(JSON.stringify(result,null,4));
// expect(result).toEqual(expected);

});

});
3 changes: 2 additions & 1 deletion src/xmlparser/OptionsBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const defaultOptions = {
transformAttributeName: false,
updateTag: function(tagName, jPath, attrs){
return tagName
}
},
// skipEmptyListItem: false
};

const buildOptions = function(options) {
Expand Down

0 comments on commit aa5d731

Please sign in to comment.