Skip to content

Commit

Permalink
update package for new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
amitguptagwl committed Feb 4, 2022
1 parent 263141b commit f5c856b
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 51 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
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.2 / 2022-02-04**
* builder supports `suppressUnpairedNode`
* parser supports `ignoreDeclaration` and `ignorePiTags`
* fix: when comment is parsed as text value if given as `<!--> ...` #423
* builder supports decoding `&`

**4.0.1 / 2022-01-08**
* fix builder for pi tag
* fix: support suppressBooleanAttrs by builder
Expand Down
89 changes: 70 additions & 19 deletions docs/v4/2.XMLparseOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To allow attributes without value.

By default boolean attributes are ignored
```js
const xmlData = `<root a="nice" checked><a>wow</a></root>`;
const xmlDataStr = `<root a="nice" checked><a>wow</a></root>`;

const options = {
ignoreAttributes: false,
Expand All @@ -39,7 +39,7 @@ Output
```
Once you allow boolean attributes, they are parsed and set to `true`.
```js
const xmlData = `<root a="nice" checked><a>wow</a></root>`;
const xmlDataStr = `<root a="nice" checked><a>wow</a></root>`;

const options = {
ignoreAttributes: false,
Expand Down Expand Up @@ -68,7 +68,7 @@ You can force FXP to render a tag with textnode using this option.

Eg
```js
const xmlData = `
const xmlDataStr = `
<root a="nice" checked>
<a>wow</a>
<a>
Expand Down Expand Up @@ -129,7 +129,7 @@ Output when `alwaysCreateTextNode: true`
To group all the attributes of a tag under given property name.

```js
const xmlData = `<root a="nice" b="very nice" ><a>wow</a></root>`;
const xmlDataStr = `<root a="nice" b="very nice" ><a>wow</a></root>`;

const options = {
ignoreAttributes: false,
Expand Down Expand Up @@ -157,7 +157,7 @@ Output
To recognize attributes in the JS object separately. You can prepend some string with each attribute name.

```js
const xmlData = `<root a="nice" ><a>wow</a></root>`;
const xmlDataStr = `<root a="nice" ><a>wow</a></root>`;

const options = {
ignoreAttributes: false,
Expand Down Expand Up @@ -198,7 +198,7 @@ If `cdataPropName` is not set to some property name, then CDATA values are merge

Eg
```js
const xmlData = `
const xmlDataStr = `
<a>
<name>name:<![CDATA[<some>Jack</some>]]><![CDATA[Jack]]></name>
</a>`;
Expand Down Expand Up @@ -241,7 +241,7 @@ If `commentPropName` is set to some property name, then comments are parsed from

Eg
```js
const xmlData = `
const xmlDataStr = `
<!--Students grades are uploaded by months-->
<class_list>
<student>
Expand Down Expand Up @@ -277,13 +277,14 @@ Output

## htmlEntities
FXP by default parse XMl entities if `processEntities: true`. You can set `htmlEntities` to parse HTML entities. Check [entities](./5.Entities.md) section for more information.

## ignoreAttributes

By default `ignoreAttributes` is set to `true`. It means, attributes are ignored by the parser. If you set any configuration related to attributes without setting `ignoreAttributes: false`, it is useless.

Eg
```js
const xmlData = `<root a="nice" ><a>wow</a></root>`;
const xmlDataStr = `<root a="nice" ><a>wow</a></root>`;

const options = {
// ignoreAttributes: false,
Expand All @@ -301,13 +302,63 @@ Output
}
```

## ignoreDeclaration

As many users want to ignore XML declaration tag to be ignored from parsing output, they can use `ignoreDeclaration: true`.

Eg
```js
const xmlDataStr = `<?xml version="1.0"?>
<?elementnames <fred>, <bert>, <harry> ?>
<h1></h1>`;

const options = {
ignoreDeclaration: true,
attributeNamePrefix : "@_"
};
const parser = new XMLParser(options);
const output = parser.parse(xmlDataStr);
```
Output
```json
{
"?elementnames": "",
"h1": ""
}
```

## ignorePiTags


As many users want to ignore PI tags to be ignored from parsing output, they can use `ignorePiTags: true`.

Eg
```js
const xmlDataStr = `<?xml version="1.0"?>
<?elementnames <fred>, <bert>, <harry> ?>
<h1></h1>`;

const options = {
ignoreDeclaration: true,
ignorePiTags: true,
attributeNamePrefix : "@_"
};
const parser = new XMLParser(options);
const output = parser.parse(xmlDataStr);
```
Output
```json
{
"h1": ""
}
```
## isArray

Whether a single tag should be parsed as an array or an object, it can't be decided by FXP. Hence `isArray` method can help users to take the decision if a tag should be parsed as an array.

Eg
```js
const xmlData = `
const xmlDataStr = `
<root a="nice" checked>
<a>wow</a>
<a>
Expand Down Expand Up @@ -361,7 +412,7 @@ FXP uses [strnum](https://github.com/NaturalIntelligence/strnum) library to pars

Eg
```js
const xmlData = `
const xmlDataStr = `
<root>
<a>-0x2f</a>
<a>006</a>
Expand Down Expand Up @@ -395,7 +446,7 @@ Output

Eg
```js
const xmlData = `
const xmlDataStr = `
<root a="nice" checked enabled="true" int="32" int="34">
<a>wow</a>
</root>`;
Expand Down Expand Up @@ -453,7 +504,7 @@ Error: Attribute 'int' is repeated.:1:48

Eg
```js
const xmlData = `
const xmlDataStr = `
<root>
35<nested>34</nested>
</root>`;
Expand Down Expand Up @@ -575,7 +626,7 @@ Remove namespace string from tag and attribute names.

Default is `removeNSPrefix: false`
```js
const xmlData = `<root some:a="nice" ><any:a>wow</any:a></root>`;
const xmlDataStr = `<root some:a="nice" ><any:a>wow</any:a></root>`;

const options = {
ignoreAttributes: false,
Expand All @@ -597,7 +648,7 @@ Output

Setting `removeNSPrefix: true`
```js
const xmlData = `<root some:a="nice" ><any:a>wow</any:a></root>`;
const xmlDataStr = `<root some:a="nice" ><any:a>wow</any:a></root>`;

const options = {
ignoreAttributes: false,
Expand All @@ -623,7 +674,7 @@ At particular point, if you don't want to parse a tag and it's nested tags then

Eg
```js
const xmlData = `
const xmlDataStr = `
<root a="nice" checked>
<a>wow</a>
<a>
Expand Down Expand Up @@ -684,7 +735,7 @@ With `tagValueProcessor` you can control how and which tag value should be parse

Eg
```js
const xmlData = `
const xmlDataStr = `
<root a="nice" checked>
<a>wow</a>
<a>
Expand Down Expand Up @@ -736,7 +787,7 @@ Text value of a tag is parsed to `#text` property by default. You can always cha

Eg
```js
const xmlData = `
const xmlDataStr = `
<a>
text<b>alpha</b>
</a>`;
Expand All @@ -763,7 +814,7 @@ Remove surrounding whitespace from tag or attribute value.

Eg
```js
const xmlData = `
const xmlDataStr = `
<root attri=" ibu te ">
35 <nested> 34</nested>
</root>`;
Expand Down Expand Up @@ -811,7 +862,7 @@ Unpaired Tags are the tags which don't have matching closing tag. Eg `<br>` in H

Eg
```js
const xmlData = `
const xmlDataStr = `
<rootNode>
<tag>value</tag>
<empty />
Expand Down
16 changes: 11 additions & 5 deletions docs/v4/3.XMLBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ Outout
<b/>
```

## suppressUnpairedNode

To supress an unpared 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.

Expand Down Expand Up @@ -172,18 +176,20 @@ Output
<rootNode>
<tag>value</tag>
<empty></empty>
<unpaired></unpaired>
<unpaired></unpaired>
<unpaired></unpaired>
<unpaired/>
<unpaired/>
<unpaired/>
</rootNode>
```

when you sets `suppressEmptyNode: true`;
when you sets `suppressUnpairedNode: true`;

```xml
<rootNode>
<tag>value</tag>
<empty />
<empty></empty>
<unpaired>
<unpaired>
<unpaired>
</rootNode>
```
Expand Down
2 changes: 1 addition & 1 deletion lib/fxbuilder.min.js

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

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

Large diffs are not rendered by default.

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.

Loading

0 comments on commit f5c856b

Please sign in to comment.