Skip to content

Commit

Permalink
Merge branch 'master' into fix/types
Browse files Browse the repository at this point in the history
  • Loading branch information
monholm committed May 7, 2024
2 parents af7dd92 + 9118736 commit 4d53abd
Show file tree
Hide file tree
Showing 73 changed files with 4,501 additions and 1,228 deletions.
6 changes: 3 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
# Type
Please mention the type of PR
<!-- choose one by changing [ ] to [x] -->
* [ ]Bug Fix
* [ ]Refactoring / Technology upgrade
* [ ]New Feature
* [ ] Bug Fix
* [ ] Refactoring / Technology upgrade
* [ ] New Feature

**Note** : Please ensure that you've read contribution [guidelines](https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/CONTRIBUTING.md) before raising this PR. If your PR is in progress, please prepend `[WIP]` in PR title. Your PR will be reviewed when `[WIP]` will be removed from the PR title.

Expand Down
2 changes: 1 addition & 1 deletion .publishrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"confirm": true,
"publishCommand": "npm publish",
"publishTag": "latest",
"prePublishScript": "npm test",
"prePublishScript": "npm test && npm test-types",
"postPublishScript": false
}
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
Note: If you find missing information about particular minor version, that version must have been changed without any functional change in this library.

**4.3.6 / 2024-03-16**
* Add support for parsing HTML numeric entities (#645) (By [Jonas Schade ](https://github.com/DerZade))

**4.3.5 / 2024-02-24**
* code for v5 is added for experimental use

**4.3.4 / 2024-01-10**
* fix: Don't escape entities in CDATA sections (#633) (By [wackbyte](https://github.com/wackbyte))

**4.3.3 / 2024-01-10**
* Remove unnecessary regex

**4.3.2 / 2023-10-02**
* fix `jObj.hasOwnProperty` when give input is null (By [Arda TANRIKULU](https://github.com/ardatan))

**4.3.1 / 2023-09-24**
* revert back "Fix typings for builder and parser to make return type generic" to avoid failure of existing projects. Need to decide a common approach.

**4.3.0 / 2023-09-20**
* Fix stopNodes to work with removeNSPrefix (#607) (#608) (By [Craig Andrews]https://github.com/candrews))
* Fix #610 ignore properties set to Object.prototype
* Fix typings for builder and parser to make return type generic (By [Sarah Dayan](https://github.com/sarahdayan))

**4.2.7 / 2023-07-30**
* Fix: builder should set text node correctly when only textnode is present (#589) (By [qianqing](https://github.com/joneqian))
* Fix: Fix for null and undefined attributes when building xml (#585) (#598). A null or undefined value should be ignored. (By [Eugenio Ceschia](https://github.com/cecia234))

**4.2.6 / 2023-07-17**
* Fix: Remove trailing slash from jPath for self-closing tags (#595) (By [Maciej Radzikowski](https://github.com/m-radzikowski))

**4.2.5 / 2023-06-22**
* change code implementation

**4.2.4 / 2023-06-06**
* fix security bug

**4.2.3 / 2023-06-05**
* fix security bug

**4.2.2 / 2023-04-18**
* fix #562: fix unpaired tag when it comes in last of a nested tag. Also throw error when unpaired tag is used as closing tag

Expand Down
52 changes: 28 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# [fast-xml-parser](https://www.npmjs.com/package/fast-xml-parser)
[![Backers on Open Collective](https://opencollective.com/fast-xml-parser/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/fast-xml-parser/sponsors/badge.svg)](#sponsors) [![Known Vulnerabilities](https://snyk.io/test/github/naturalintelligence/fast-xml-parser/badge.svg)](https://snyk.io/test/github/naturalintelligence/fast-xml-parser)
[![Known Vulnerabilities](https://snyk.io/test/github/naturalintelligence/fast-xml-parser/badge.svg)](https://snyk.io/test/github/naturalintelligence/fast-xml-parser)
[![NPM quality][quality-image]][quality-url]
[![Coverage Status](https://coveralls.io/repos/github/NaturalIntelligence/fast-xml-parser/badge.svg?branch=master)](https://coveralls.io/github/NaturalIntelligence/fast-xml-parser?branch=master)
[<img src="https://img.shields.io/badge/Try-me-blue.svg?colorA=FFA500&colorB=0000FF" alt="Try me"/>](https://naturalintelligence.github.io/fast-xml-parser/)
Expand All @@ -11,20 +11,30 @@

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

> Looking for maintainers
> XML Parser v5 is added for experimental use
> https://solothought.com
Support this project by becoming a **Sponsor**.

Click on Sponsor button above or
Sponsor this project 👉
<a href="https://github.com/sponsors/NaturalIntelligence">
<img src="https://raw.githubusercontent.com/NaturalIntelligence/ThankYouBackers/main/github_sponsor.png" width="200" />
</a>
<a href="https://opencollective.com/fast-xml-parser/donate" target="_blank">
<img src="https://opencollective.com/fast-xml-parser/donate/[email protected]?color=blue" width=200 />
</a>
<a href="https://paypal.me/naturalintelligence"> <img src="static/img/support_paypal.svg" alt="Stubmatic donate button" width="200"/></a>


### Sponsors
### Current Sponsors

Check the complete list at [ThankYouBackers](https://github.com/NaturalIntelligence/ThankYouBackers) for our sponsors and supporters.

Through Github

<a href="https://github.com/skunkteam" target="_blank"><img src="https://avatars.githubusercontent.com/u/46373671?s=60" width="60px"></a>
<a href="https://github.com/getsentry" target="_blank"><img src="https://avatars.githubusercontent.com/u/1396951?s=60" width="60px"></a>

Through OpenCollective

<a href="https://github.com/getsentry" target="_blank"><img src="https://user-images.githubusercontent.com/7692328/204701653-ce369b29-6fdb-48f2-9848-593d04628a2b.png" width="60px"></a>
<a href="https://opencollective.com/fast-xml-parser/sponsor/0/website" target="_blank"><img src="https://opencollective.com/fast-xml-parser/sponsor/0/avatar.svg"></a>
<a href="https://opencollective.com/fast-xml-parser/sponsor/1/website" target="_blank"><img src="https://opencollective.com/fast-xml-parser/sponsor/1/avatar.svg"></a>
<a href="https://opencollective.com/fast-xml-parser/sponsor/2/website" target="_blank"><img src="https://opencollective.com/fast-xml-parser/sponsor/2/avatar.svg"></a>
Expand All @@ -37,8 +47,6 @@ Click on Sponsor button above or
<a href="https://opencollective.com/fast-xml-parser/sponsor/9/website" target="_blank"><img src="https://opencollective.com/fast-xml-parser/sponsor/9/avatar.svg"></a>


Check [ThankYouBackers](https://github.com/NaturalIntelligence/ThankYouBackers) for our supporters

## Users

<a href="https://github.com/renovatebot/renovate" title="renovate" ><img src="https://avatars1.githubusercontent.com/u/38656520" width="60px" ></a>
Expand All @@ -56,9 +64,13 @@ Check [ThankYouBackers](https://github.com/NaturalIntelligence/ThankYouBackers)
<a href="https://github.com/postmanlabs" title="postman" > <img src="https://user-images.githubusercontent.com/7692328/204835529-e9e290ad-696a-49ad-9d34-08e955704715.png" width="60px" ></a>
<a href="https://github.com/react-native-community" title="React Native Community" > <img src="https://avatars.githubusercontent.com/u/20269980?v=4" width="60px" ></a>

Check the list of all known users [here](./USERs.md);
Check the bigger [list](./USERs.md)

<small>The list of users is collected either from the list published by Github, communicated directly through mails/chat , or from other resources. If you feel that your name in the above list is incorrectly published or you're not the user of this library anymore then you can inform us to remove it. We'll do the necessary changes ASAP.</small>

<small>The list of users is collected either from the list published by Github, cummunicated directly through mails/chat , or from other resources. If you feel that your name in the above list is incorrectly published or you're not the user of this library anymore then you can inform us to remove it. We'll do the necessary changes ASAP.</small>
If you want to be an anonymous user of this application and don't want to be highlighted anywhere then you can contact me at
- [email protected]
- https://linkedin.com/in/amitguptagwl/

## Main Features

Expand All @@ -80,6 +92,11 @@ Check the list of all known users [here](./USERs.md);
* Supports parsing of PI (Processing Instruction) tags with XML declaration tags
* And many more other features.

## v5
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.

Please leave a comment in discussion forum for your suggestions and if you really need v5.

## How to use

To use as package dependency
Expand Down Expand Up @@ -163,19 +180,6 @@ Check lib folder for different browser bundles

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

## Our other projects and research you must try

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


## Supporters
### Contributors
Expand Down
1 change: 1 addition & 0 deletions docs/CHECK_LIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ In general

Post release
* [ ] Tagged and Released on github `git push origin --tags`
* [ ] `git push origin master`
* [ ] Notified to the users
* [ ] Sync master and dev branches

Expand Down
8 changes: 4 additions & 4 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Thanks
I would like to thank you for your valuable time and effort and applogies if this PR is rejected due to any reason.
I would like to thank you for your valuable time and effort and apologies if this PR is rejected due to any reason.

This repository is written with the aim of providing high performance not in terms of speed only but comfortability of the user as well.
This repository is written with the aim of providing high performance, not in terms of speed only, but comfortably of the user as well.

## No rights are resserved
## No rights are reserved

Your contribution is valuable. We try to mention your name on README with the avatar. We can't promise to pay you for your contribution.

### DoD
Here is the check list to publish any change

* Changes are not half implemented due to the library limitation or any other reason.
* Changes are well discussed by raising github issue. So they are well known by other contributers and users
* Changes are well discussed by raising github issue. So they are well known by other contributors and users
* Echoing the above point. The purpose / goal for the PR should be mentioned in the description.
* Multiple unrelated changes should not be clubbed in single PR.
* Please run perf tests `$ node benchmark\XmlParser.js` or `$ node benchmark\XmlBuilder.js` before and after the changes. And mention it in PR description.
Expand Down
2 changes: 1 addition & 1 deletion docs/v3/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Validator returns the following object in case of error;
* **cdataTagName** : If specified, parser parse CDATA as nested tag instead of adding it's value to parent tag.
* **cdataPositionChar** : It'll help to covert JSON back to XML without losing CDATA position.
* **parseTrueNumberOnly**: if true then values like "+123", or "0123" will not be parsed as number.
* **arrayMode** : When `false`, a tag with single occurrence is parsed as an object but as an array in case of multiple occurences. When `true`, a tag will be parsed as an array always excluding leaf nodes. When `strict`, all the tags will be parsed as array only. When instance of `RegEx`, only tags will be parsed as array that match the regex. When `function` a tag name is passed to the callback that can be checked.
* **arrayMode** : When `false`, a tag with single occurrence is parsed as an object but as an array in case of multiple occurrences. When `true`, a tag will be parsed as an array always excluding leaf nodes. When `strict`, all the tags will be parsed as array only. When instance of `RegEx`, only tags will be parsed as array that match the regex. When `function` a tag name is passed to the callback that can be checked.
* **tagValueProcessor** : Process tag value during transformation. Like HTML decoding, word capitalization, etc. Applicable in case of string only.
* **attrValueProcessor** : Process attribute value during transformation. Like HTML decoding, word capitalization, etc. Applicable in case of string only.
* **stopNodes** : an array of tag names which are not required to be parsed. Instead their values are parsed as string.
Expand Down
2 changes: 1 addition & 1 deletion docs/v4/1.GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if(XMLValidator.validate()){
let jsonObj = parser.parse(xmlData);

const builder = new XMLBuilder();
let samleXmlData = builder.build(jsonObj);
let sampleXmlData = builder.build(jsonObj);
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/v4/2.XMLparseOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ const XMLdata = `
```

## processEntities
Set it to `true` (default) to process default and DOCTYPE entites. Check [Entities](./5.Entities.md) section for more detail. If you don't have entities in your XML document then it is recommanded to disable it `processEntities: false` for better performance.
Set it to `true` (default) to process default and DOCTYPE entities. Check [Entities](./5.Entities.md) section for more detail. If you don't have entities in your XML document then it is recommended to disable it `processEntities: false` for better performance.
## removeNSPrefix

Remove namespace string from tag and attribute names.
Expand Down Expand Up @@ -854,7 +854,7 @@ Output
}
}
```
If the tag value consists whitespaces and `trimValues: false` then value will not be parsed even if `parseTagValue:true`. Similarly, if `trimValues: true` and `parseTagValue:false` then surrounding whitespace will be removed.
If the tag value consists of whitespace only and `trimValues: false` then value will not be parsed even if `parseTagValue:true`. Similarly, if `trimValues: true` and `parseTagValue:false` then surrounding whitespace will be removed.

```js
const options = {
Expand Down
20 changes: 10 additions & 10 deletions docs/v4/3.XMLBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ const output = builder.build(cars);
To recognize attribute properties in the JS object so that they can be trimmed.

## attributesGroupName
To recognize attribute properties group in the JS object so that they can be trimmed and can form attribute expresstion for a tag.
To recognize attribute properties group in the JS object so that they can be trimmed and can form attribute expression for a tag.

This property is not supported when `preserveOrder: true` because attributes are already grouped.
## attributeValueProcessor
To customize the bahaviour of parsing an attribute value to the string value. It accepts attribute name and value.
To customize the behavior of parsing an attribute value to the string value. It accepts attribute name and value.

## cdataPropName
To recognize CDATA properties in a JS object so that they can be transformed correcty.
To recognize CDATA properties in a JS object so that they can be transformed correctly.

Eg
Input
Expand Down Expand Up @@ -113,7 +113,7 @@ Output

It is recommended to use `preserveOrder: true` when you're parsing XML to js object and building the XML back. So that the order of CDATA is maintained.
## commentPropName
To recognize comments in a JS object so that they can be transformed correcty.
To recognize comments in a JS object so that they can be transformed correctly.


Eg
Expand Down Expand Up @@ -179,7 +179,7 @@ Applicable only if `format:true` is set.
When you parse a XML using XMLParser with `preserveOrder: true`, the result JS object has different structure. So parse that structure in original XML, you should set the same option while building the XML from that js object.

## processEntities
Set it to `true` (default) to process XML entities. Check [Entities](./5.Entities.md) section for more detail. If you don't have entities in your XML document then it is recommanded to disable it `processEntities: false` for better performance.
Set it to `true` (default) to process XML entities. Check [Entities](./5.Entities.md) section for more detail. If you don't have entities in your XML document then it is recommended to disable it `processEntities: false` for better performance.

## oneListGroup

Expand Down Expand Up @@ -242,7 +242,7 @@ const options = {
const builder = new XMLBuilder(options);
const output = builder.build(result);
```
Outout
Output
```xml
<?textinfo whitespace is allowed?>
```
Expand All @@ -268,10 +268,10 @@ Outout

## suppressUnpairedNode

To supress an unpared tag from `<br/>` to `<br>`.
To suppress an unpaired tag from `<br/>` to `<br>`.

## tagValueProcessor
To customize the bahaviour of parsing the text value of a tag to the string value. It accepts tag name and value.
To customize the behavior of parsing the text value of a tag to the string value. It accepts tag name and value.

## textNodeName
To recognize text value for a tag in the JS object so that they can be properly assigned to the tag.
Expand All @@ -295,7 +295,7 @@ const options = {
unpairedTags: ["unpaired"]
};
const parser = new XMLParser(options);
const result = parser.parse(xmlDataStr);
const result = parser.parse(xmlData);

const builder = new XMLBuilder(options);
const output = builder.build(result);
Expand Down Expand Up @@ -462,4 +462,4 @@ Output



[> Next: XmlValidator](./4.XMLValidator.md)
[> Next: XmlValidator](./4.XMLValidator.md)
6 changes: 4 additions & 2 deletions docs/v4/5.Entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Following attacks are possible due to entity processing
* Denial-of-Service Attacks
* Classic XXE
* Advanced XXE
* Server-Side Requst Forgery (SSRF)
* Server-Side Request Forgery (SSRF)
* XInclude
* XSLT

Expand All @@ -132,11 +132,13 @@ Following HTML entities are supported by the parser by default when `htmlEntitie
|| Indian Rupee | `&inr;` | `&#8377;` |
---

In addition, [numeric character references](https://html.spec.whatwg.org/multipage/syntax.html#syntax-charref) are also supported. Both decimal (`num_dec`) and hexadecimal(`num_hex`).

In future version of FXP, we'll be supporting more features of DOCTYPE such as `ELEMENT`, reading content for an entity from a file etc.

## External Entities

You can set external entites without using DOCTYPE.
You can set external entities without using DOCTYPE.

```js
const xmlData = `<note>&unknown;&#xD;last</note> `;
Expand Down
2 changes: 1 addition & 1 deletion docs/v4/7.PITags.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Processing Instructions are supported by Fast XML parser. However, they're treated as normal tags from parsing perpective. Hence, following properties are required to be set for attributes processing;
Processing Instructions are supported by Fast XML parser. However, they're treated as normal tags from the parsing perspective. Hence, the following properties are required to be set for attributes processing;

```js
ignoreAttributes: false,
Expand Down
24 changes: 24 additions & 0 deletions docs/v5/1. Getting Started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@


Example with no configuration

```js
const XMLParser = require("fast-xml-parser/v5/XMLParser")
const parser = new XMLParser();
//read xmlData your own
let result = parser.parse(xmlData, true);
```

The default response of parse is built by `JsObjOutputBuilder`. FXP v5 comes with 2 more output builders. And you can set your custom output builder too to customize the output.

```js
const JsObjOutputBuilder = require("fast-xml-parser/v5/OutputBuilders/JsObjBuilder");

const parser = new XMLParser({
OutputBuilder: new JsObjOutputBuilder()
});
//read xmlData your own
let result = parser.parse(xmlData, true);
```


5 changes: 5 additions & 0 deletions docs/v5/2. Features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Features
- **Output Builder**: Many projects want a different parsing result. Some wants to group the attributes, some wants to skip an attribute or tag, some wants index number with each property, and some wants to group some properties in array. So FXP v5 come up with 3 output builders. User can customize their behavior and use their own custom builder too.
- You can control the sequence of value parsing for a tag or attribute
- You can pass a string or bytes array as input.
- many to be listed
Loading

0 comments on commit 4d53abd

Please sign in to comment.