Skip to content

Commit

Permalink
update README and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
amitguptagwl committed Nov 17, 2021
1 parent c041a0a commit 5260c56
Show file tree
Hide file tree
Showing 9 changed files with 432 additions and 292 deletions.
18 changes: 18 additions & 0 deletions docs/CHANGELOG.md → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
Note: If you find missing information about particular minor version, that version must have been changed without any functional change in this library.

**⚠️ 4.0.0-beta.0 / 2021-11-16**
* Name change of many configuration properties.
* `attrNodeName` to `attributesGroupName`
* `attrValueProcessor` to `attributeValueProcessor`
* `parseNodeValue` to `parseTagValue`
* `ignoreNameSpace` to `removeNSPrefix`
* `numParseOptions` to `numberParseOptions`
* spelling correction for `suppressEmptyNode`
* Name change of cli and browser bundle to **fxparser**
* `isArray` option is added to parse a tag into array
* `preserveOrder` option is added to render XML in such a way that the result js Object maintains the order of properties same as in XML.
* Processing behaviour of `tagValueProcessor` and `attributeValueProcessor` are changes with extra input parameters
* j2xparser is renamed to XMLBuilder.
* You need to build XML parser instance for given options first before parsing XML.
* fix #327, #336: throw error when extra text after XML content
* fix #330: attribute value can have '\n',
* fix #350: attrbiutes can be separated by '\n' from tagname

3.21.1 / 2021-10-31
* Correctly format JSON elements with a text prop but no attribute props ( By [haddadnj](https://github.com/haddadnj) )

Expand Down
352 changes: 77 additions & 275 deletions README.md

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions USERs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Please raise an issue or PR (recommended) to add your name to our User's list

<a href="https://github.com/NaturalIntelligence/imglab" title="imglab" ><img src="https://github.com/NaturalIntelligence/imglab/blob/master/img/imglab_logo.png?raw=true" width="80px" ></a>
<a href="https://github.com/NaturalIntelligence/Stubmatic" title="stubmatic" ><img src="https://camo.githubusercontent.com/ff711425dc2286cd215637b7114eb43e571f001d/68747470733a2f2f6e61747572616c696e74656c6c6967656e63652e6769746875622e696f2f537475626d617469632f696d672f737475626d617469635f6c6f676f2e706e673f7261773d74727565" width="80px" ></a>
<a href="https://github.com/muneem4node/muneem" title="Muneem" ><img src="https://github.com/muneem4node/muneem/raw/master/static/muneem.png?raw=true" width="80px" ></a>
<a href="https://github.com/badges/shields" title="shields" ><img src="https://avatars2.githubusercontent.com/u/6254238" width="80px" ></a>
<a href="https://github.com/renovatebot/renovate" title="renovate" ><img src="https://avatars1.githubusercontent.com/u/38656520" width="80px" ></a>
<a href="https://vmware.com/" title="vmware" > <img src="https://avatars0.githubusercontent.com/u/473334" width="80px" ></a>
<a href="https://opensource.microsoft.com/" title="microsoft" > <img src="https://avatars0.githubusercontent.com/u/6154722" width="80px" ></a>
<a href="https://github.com/notable/notable" title="notable" > <img src="https://avatars3.githubusercontent.com/u/46467536" width="80px" ></a>
<a href="http://ibm.github.io/" title="IBM" > <img src="https://avatars2.githubusercontent.com/u/1459110" width="80px" ></a>
<a href="https://www.ft.com/" title="Financial Times" > <img src="https://avatars2.githubusercontent.com/u/3502508" width="80px" ></a>
<a href="https://github.com/camunda" title="camunda BPM" > <img src="https://avatars3.githubusercontent.com/u/2443838" width="80px" ></a>
<a href="https://github.com/AnyChart" title="AnyChart" > <img src="https://avatars0.githubusercontent.com/u/703373" width="80px" ></a>
<a href="https://github.com/magda-io" title="magda-io" > <img src="https://avatars0.githubusercontent.com/u/40348684" width="80px" ></a>
<a href="https://github.com/geistinteractive" title="Geist Interactive" > <img src="https://avatars0.githubusercontent.com/u/11617965" width="80px" ></a>
<a href="https://www.tourstream.eu/" title="tourstream" > <img src="https://avatars1.githubusercontent.com/u/23242088" width="80px" ></a>
<a href="https://www.atomist.com/" title="Atomist" > <img src="https://avatars3.githubusercontent.com/u/19392" width="80px" ></a>
<a href="http://www.opuscapita.com/" title="OpusCapita" > <img src="https://avatars1.githubusercontent.com/u/23256480" width="80px" ></a>
<a href="https://nevatrip.ru/" title="nevatrip" > <img src="https://avatars2.githubusercontent.com/u/35730984" width="80px" ></a>
<a href="http://www.smartbear.com" title="SmartBear Software" > <img src="https://avatars2.githubusercontent.com/u/1644671" width="80px" ></a>
<a href="http://eosnavigator.com/" title="nevatrip" > <img src="https://avatars1.githubusercontent.com/u/40260563" width="80px" ></a>
<a href="http://nasa.github.io/" title="NASA" > <img src="https://avatars0.githubusercontent.com/u/848102" width="80px" ></a>
<a href="http://qgis.org/" title="QGIS" > <img src="https://avatars2.githubusercontent.com/u/483444" width="80px" ></a>
<a href="http://www.craft.ai/" title="craft ai" > <img src="https://avatars1.githubusercontent.com/u/12046764" width="80px" ></a>
<a href="http://brownspace.org/" title="Brown Space Engineering" > <img src="https://avatars2.githubusercontent.com/u/5504507" width="80px" ></a>
<a href="http://www.appcelerator.com/" title="Team Appcelerator" > <img src="https://avatars1.githubusercontent.com/u/82188" width="80px" ></a>
<a href="https://xmllint.com/" title="XML Lint" > <img src="https://xmllint.com/assets/logo.png" width="80px" ></a>
<a href="https://github.com/prettier" title="Prettier" > <img src="https://avatars0.githubusercontent.com/u/25822731" width="80px" ></a>
<a href="https://github.com/dolanmiu/docx" title="docx" > <img src="https://i.imgur.com/37uBGhO.gif" width="80px" ></a>
<a href="http://orange-opensource.github.io/" title="Open Source by Orange" > <img src="https://avatars3.githubusercontent.com/u/1506386" width="80px" ></a>
<a href="http://www.ybrain.com/" title="YBRAIN Inc." > <img src="https://avatars2.githubusercontent.com/u/38232440" width="80px" ></a>
<a href="http://99bitcoins.com/" title="99 bitcoins" > <img src="https://avatars0.githubusercontent.com/u/9527779" width="80px" ></a>
<a href="https://wechaty.github.io/wechaty/" title="Wechaty" > <img src="https://avatars0.githubusercontent.com/u/21285357" width="80px" ></a>
<a href="https://opendatakit.org" title="Open Data Kit" > <img src="https://avatars0.githubusercontent.com/u/6222985" width="80px" ></a>
<a href="https://ridibooks.com" title="RIDI Books" > <img src="https://avatars1.githubusercontent.com/u/24955411" width="80px" ></a>
<a href="http://signalk.org" title="Signal K" > <img src="https://avatars1.githubusercontent.com/u/7126740" width="80px" ></a>
<a href="http://brain.js.org/" title="brain.js" > <img src="https://avatars2.githubusercontent.com/u/23732838" width="80px" ></a>
<a href="https://skygear.io/" title="Skegear" > <img src="https://avatars1.githubusercontent.com/u/15025887" width="80px" ></a>
<a href="https://npmjs.com/" title="npm" > <img src="https://avatars0.githubusercontent.com/u/6078720" width="80px" ></a>
<a href=" https://www.mindpointgroup.com" title="mindpointgroup" > <img src="https://avatars1.githubusercontent.com/u/6413533" width="80px" ></a>
<a href="http://www.acuantcorp.com/" title="Acuant Inc" > <img src="https://avatars3.githubusercontent.com/u/11580319?s=200&v=4" width="80px" ></a>
<a href="https://www.wazuh.com/" title="wazuh" > <img src="https://avatars2.githubusercontent.com/u/13752566" width="80px" ></a>
<a href="https://orbs.com/" title="ORBS The Hybrid Blockchain" > <img src="https://avatars1.githubusercontent.com/u/33665977" width="80px" ></a>
<a href="https://texlab.netlify.com/" title="latex-lsp" > <img src="https://avatars1.githubusercontent.com/u/48360002" width="80px" ></a>
<a href="https://frontside.io/" title="The Frontside " > <img src="https://avatars1.githubusercontent.com/u/223096" width="80px" ></a>
<a href="https://creditsense.com.au/" title="Credit Sense Australia " > <img src="https://avatars0.githubusercontent.com/u/46947118" width="80px" ></a>
<a href="https://www.hustunique.com/" title="UniqueStudio" > <img src="https://avatars1.githubusercontent.com/u/4847684" width="80px" ></a>
<a href="http://www.openforis.org/" title="Open Foris" > <img src="https://avatars2.githubusercontent.com/u/1212750" width="80px" ></a>
<a href="#" title="NHS Connect" > <img src="https://avatars3.githubusercontent.com/u/20316669" width="80px" ></a>
<a href="https://tradle.io/" title="Tradle" > <img src="https://avatars2.githubusercontent.com/u/9482126" width="80px" ></a>
<a href="http://www.anl.gov/" title="Argonne National Laboratory" > <img src="https://avatars0.githubusercontent.com/u/10468712" width="80px" ></a>
<a href="https://simpleicons.org/" title="Simple Icons" > <img src="https://avatars2.githubusercontent.com/u/29872746" width="80px" ></a>
<a href="https://stoplight.io/" title="Stoplight" > <img src="https://avatars1.githubusercontent.com/u/10767217" width="80px" ></a>
<a href="http://www.fda.gov/" title="Food and Drug Administration " > <img src="https://avatars2.githubusercontent.com/u/6471964" width="80px" ></a>
<a href="http://www.magento.com/" title="Magento" > <img src="https://avatars2.githubusercontent.com/u/168457" width="80px" ></a>

12 changes: 5 additions & 7 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ I would like to thank you for your valuable time and effort and applogies if thi

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

If your change is not a bug fix please check **nexttodo.md** before implementing any new feature.

## No rights are resserved

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.
Expand All @@ -16,17 +14,17 @@ Here is the check list to publish any change
* Changes are well discussed by raising github issue. So they are well known by other contributers 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\perfTest3.js` before and after the changes. And mention it in PR description.
* Please run perf tests `$ node benchmark\XmlParser.js` or `$ node benchmark\XmlBuilder.js` before and after the changes. And mention it in PR description.
* If you are adding any dependency (specially if it is not the dev dependency) please check that
* it is not dependent on other language packages like c/c++
* the package is not very old, very new, discontinued, or has any vulnerability etc.
* please check the performance and size of package
* please check alternate available options
* Please write tests for the new changes
* Don't forget to write tests for negative cases
* Don't comment existing test case.
* Don't comment existing test cases.

Changes need to do be done by owner
Changes need to do be done by maintainers and should not to be the part of PR by other contributors;
* Increase the version number
* Update the change log & README if required
* Generate the browser bundle
Expand All @@ -38,10 +36,10 @@ Note that publishing changes or accepting any PR may take time. So please keep p
### Guidelines for first time contributors

* https://github.com/Roshanjossey/first-contributions
* **Don't stretch**. If you complete an issue in long time, there is a possibility that other developers finish their part and you face code conflicts which may increase code complexity for you. So it is always good to complete an issue ASAP.
* **Don't stretch**. If you complete an issue in long time, there is a possibility that other developers finish their part first and you face code conflicts which may increase code complexity for you. So it is always good to complete an issue ASAP.
* Please refrain to work on multiple issues marked with "first-timers-only" in the same repo. Ask and help your friends and colleagues to attempt rest issues.
* Please claim the issue and clear your doubts before raising PR. So other users will not start working on the same issue.
* Mention the issue number either in PR detail or in commit message.
* Keep increasing the level of challenge.
* Don't hesitate to question on github issue or on twitter.
* Don't hesitate to question on github issue or on stackoverflow.

Binary file added docs/imgs/XMLBuilder_v4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/imgs/XMLParser_large_v4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/imgs/XMLParser_v4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
247 changes: 237 additions & 10 deletions docs/v4/3.XMLBuilder.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,240 @@
XML Builder can be used to parse a JS object into XML. It supports following options;

* attributeNamePrefix
* attributesGroupName
* attributeValueProcessor
* cdataTagName
* format
* ignoreAttributes
* indentBy
* suppressEmptyNode
* tagValueProcessor
* textNodeName
```js
const {XMLBuilder} = require('fast-xml-parser');

const options = {
ignoreAttributes : false
};

const builder = new XMLBuilder(options);
let xmlDataStr = builder.build(jObj);
```


## arrayNodeName
When you build XML from an array, it's better to set `arrayNodeName` option to some name.

```js
const cars = [
{
"color": "purple",
"type": "minivan",
"registration": "2020-02-03",
"capacity": 7
},
{
"color": "orange",
"type": "SUV",
"registration": "2021-05-17",
"capacity": 4
},
];
const builder = new XMLBuilder({
arrayNodeName: "car"
});
const output = builder.build(cars);
```
```xml
<car>
<color>purple</color>
<type>minivan</type>
<registration>2020-02-03</registration>
<capacity>7</capacity>
</car>
<car>
<color>orange</color>
<type>SUV</type>
<registration>2021-05-17</registration>
<capacity>4</capacity>
</car>
```

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

## attributeValueProcessor
To customize the bahaviour of parsing an attribute value to the string value. It accepts attribute name and value.

## cdataTagName
To recognize CDATA properties in a JS object so that they can be transformed correcty. This option is useful only if `preserveOrder: true`

## format
By default, parsed XML is single line XML string. By `format: true`, you can format it for better view.

## ignoreAttributes
Don't consider attributes while building XML. Other attributes related properties should be set to correctly identifying an attribute property.

## indentBy
Applicable only if `format:true` is set.

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

## suppressEmptyNode
Tags with no text value would be parsed as empty tags.
Input
```js
const builder = new XMLBuilder({
arrayNodeName: "any", //not effective
suppressEmptyNode: true
});
const output = builder.build({
a: 32,
b: ""
});
```
Outout
```xml
<a>32</a>
<b/>
```

## tagValueProcessor
To customize the bahaviour 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.

# Restoring original XML

**Example 1**

When you use XML Parser with `alwaysCreateTextNode: true`, it doesn't impact XMLBuilder result

```js
const XMLdata = `
<car>
<color>purple</color>
<type>minivan</type>
<registration>2020-02-03</registration>
<capacity>7</capacity>
</car>`;

const parser = new XMLParser({
alwaysCreateTextNode: true,
});
let result = parser.parse(XMLdata);
// console.log(JSON.stringify(result, null,4));

const builder = new XMLBuilder({ format: true });
const output = builder.build(result);
```
Output
```xml
<car>
<color>purple</color>
<type>minivan</type>
<registration>2020-02-03</registration>
<capacity>7</capacity>
</car>
```

**Example 2**

When you use XML Parser with `isArray`, it doesn't impact XMLBuilder result under some extent.


```js
const XMLdata = `
<car>
<color>purple</color>
<type>minivan</type>
<registration>2020-02-03</registration>
<capacity>7</capacity>
</car>`;

const parser = new XMLParser({
isArray: (tagName, jPath, isLeafNode, isAttribute) => {
if(isLeafNode) return true;
}
});
let result = parser.parse(XMLdata);
// console.log(JSON.stringify(result, null,4));

const builder = new XMLBuilder();
const output = builder.build(result);
```
Output
```xml
<car>
<color>purple</color>
<type>minivan</type>
<registration>2020-02-03</registration>
<capacity>7</capacity>
</car>
```

**Example 3**

When you use XML Parser with `preserveOrder`, you should use the same option with XMLBuilder.


```js
const XMLdata = `
<car>
<color>purple</color>
<type>minivan</type>
<registration>2020-02-03</registration>
<capacity>7</capacity>
</car>`;

const parser = new XMLParser({
preserveOrder: true
});
let result = parser.parse(XMLdata);
// console.log(JSON.stringify(result, null,4));

const builder = new XMLBuilder({ preserveOrder: true });
const output = builder.build(result);
```
Output
```xml
<car>
<color>purple</color>
<type>minivan</type>
<registration>2020-02-03</registration>
<capacity>7</capacity>
</car>
```

**Example 4**

You should set `attributeNamePrefix` and other properties to the same value for XML Parser and XMLBuilder.


```js
const XMLdata = `
<car>
<color alpha="7">purple</color>
<type>minivan</type>
<registration>2020-02-03</registration>
<capacity>7</capacity>
</car>`;

const options = {
ignoreAttributes: false,
attributeNamePrefix: "@@",
format: true
};
const parser = new XMLParser(options);
let result = parser.parse(XMLdata);
// console.log(JSON.stringify(result, null,4));

const builder = new XMLBuilder(options);
const output = builder.build(result);
```
Output
```xml
<car>
<color alpha="7">purple</color>
<type>minivan</type>
<registration>2020-02-03</registration>
<capacity>7</capacity>
</car>
```

[> Next: XmlValidator](./4.XMLValidator.md)
Loading

0 comments on commit 5260c56

Please sign in to comment.