Skip to content

Commit 0a328ed

Browse files
committed
update v3 information
1 parent d423f3b commit 0a328ed

File tree

4 files changed

+50
-27
lines changed

4 files changed

+50
-27
lines changed

README.md

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var fastXmlParser = require('fast-xml-parser');
4343
var jsonObj = fastXmlParser.parse(xmlData);
4444

4545
// when a tag has attributes
46+
/* upto 2.9.x
4647
var options = {
4748
attrPrefix : "@_",
4849
attrNodeName: false,
@@ -55,6 +56,18 @@ var options = {
5556
textAttrConversion : false,
5657
arrayMode : false
5758
};
59+
*/
60+
//from 3.0.0
61+
var options = {
62+
attributeNamePrefix : "@_",
63+
attrNodeName: false,
64+
textNodeName : "#text",
65+
ignoreAttributes : true,
66+
ignoreNameSpace : false,
67+
parseNodeValue : true,
68+
parseAttributeValue : false,
69+
trimValues: true, //Trim string values of tag and attributes
70+
};
5871
if(fastXmlParser.validate(xmlData)=== true){//optional
5972
var jsonObj = fastXmlParser.parse(xmlData,options);
6073
}
@@ -65,16 +78,13 @@ var jsonObj = fastXmlParser.convertToJson(tObj);
6578

6679
```
6780

68-
81+
* **attributeNamePrefix** : prepend given string to attribute name for identification
6982
* **attrNodeName**: (Valid name) Group all the attributes as properties of given name.
70-
* **ignoreNonTextNodeAttr** : Ignore attributes of non-text node.
71-
* **ignoreTextNodeAttr** : Ignore attributes for text node
83+
* **ignoreAttributes** : Ignore attributes to be parsed.
7284
* **ignoreNameSpace** : Remove namespace string from tag and attribute names.
73-
* **ignoreRootElement** : Remove root element from parsed JSON.
74-
* **textNodeConversion** : Parse the value of text node to float or integer.
75-
* **textAttrConversion** : Parse the value of an attribute to float or integer.
76-
* **arrayMode** : Put the value(s) of a tag or attribute in an array.
77-
85+
* **parseNodeValue** : Parse the value of text node to float, integer, or boolean.
86+
* **parseAttributeValue** : Parse the value of an attribute to float, integer, or boolean.
87+
* **trimValues** : trim string values of an attribute or node
7888

7989
To use from command line
8090
```bash
@@ -110,9 +120,24 @@ Why not C/C++ based libraries?
110120
Installation of such libraries fails on some OS. You may require to install missing dependency manually.
111121

112122
### Benchmark report
113-
![npm_xml2json_compare](https://cloud.githubusercontent.com/assets/7692328/22402086/7526a3a6-e5e2-11e6-8e6b-301691725c21.png)
114123

115-
Don't forget to check the performance report on [comparejs](https://naturalintelligence.github.io/comparejs/?q=xml2json).
124+
। file size | fxp 3.0 validator | fxp 3.0 parser | xml2js 0.4.19 ।
125+
। ---------- | ----------------------- | ------------------- | ------------------- ।
126+
। 1.5k | 16581.06758 | 14032.09323 | 4615.930805 ।
127+
। 1.5m | 14918.47793 | 13.23366098 | 5.90682005 ।
128+
। 13m | 1.834479235 | 1.135582008 | -1 ।
129+
। 1.3k with CDATA | 30583.35319 | 43160.52342 | 8398.556349 ।
130+
। 1.3m with CDATA | 27.29266471 | 52.68877009 | 7.966000795 ।
131+
। 1.6k with cdata,prolog,doctype | 27690.26082 | 41433.98547 | 7872.399268 ।
132+
। 98m | 0.08473858148 | 0.2600104004 | -1 ।
133+
134+
* -1 indicates error or incorrect output.
135+
136+
![npm_xml2json_compare](static/img/fxpv3-vs-xml2jsv0419_chart.png)
137+
138+
![npm_xml2json_compare](static/img/fxp-validatorv3.png)
139+
140+
116141

117142
**validator benchmark: 21000 tps**
118143

@@ -121,11 +146,10 @@ Your contribution in terms of donation, testing, bug fixes, code development etc
121146

122147
**Give a [star](https://github.com/NaturalIntelligence/fast-xml-parser)**, if you really like this project.
123148

124-
# Changes from v3 (in progress)
149+
# Changes from v3
125150

126-
* Can handle big files as well.
127-
* Validator is clubbed with parser
128-
* Meaningful error messages
151+
* It can handle big file now. Performance report is given above.
152+
* Meaningful error messages from validator
129153

130154
```
131155
"err": {
@@ -138,28 +162,26 @@ Your contribution in terms of donation, testing, bug fixes, code development etc
138162

139163
```
140164
var defaultOptions = {
141-
attrNamePrefix : "@_", //prefix for attributes
142-
attrNodeName: false, //Group attributes in separate node
165+
attributeNamePrefix : "@_", //prefix for attributes
166+
attrNodeName: false, //Group attributes in separate node
143167
textNodeName : "#text", //Name for property which will have value of the node in case nested nodes are present, or attributes
144-
ignoreAttributes : true, //ignore attributes
145-
allowBooleanAttributes : false, //A tag can have attributes without any value
146-
ignoreNameSpace : false, //ignore namespace from the name of a tag and attribute. It also removes xmlns attribute
147-
parseNodeValue : true, //convert the value of node to primitive type. E.g. "2" -> 2
148-
parseAttributeValue : false, //convert the value of attribute to primitive type. E.g. "2" -> 2
149-
trimValues: true, //Trim string values of tag and attributes
168+
ignoreAttributes : true, //ignore attributes
169+
ignoreNameSpace : false, //ignore namespace from the name of a tag and attribute. It also removes xmlns attribute
170+
parseNodeValue : true, //convert the value of node to primitive type. E.g. "2" -> 2
171+
parseAttributeValue : false, //convert the value of attribute to primitive type. E.g. "2" -> 2
172+
trimValues: true, //Trim string values of tag and attributes
150173
};
151174
```
152175
* Parse boolean values as well. E.g. `"true"` to `true`
153176
* You can set pasrer not to *trim* whitespaces from attribute or tag /node value.
154177
* Tag / node and attribute value is by default HTML decoded. However CDATA value will not be decoded.
155178
* Tag / node value will not be parsed if CDATA presents.
156-
* Few validation bugs are also fixed
179+
* Few validation and parsing bugs are also fixed
157180

158181

159182
Some of my other NPM pojects
160183
- [stubmatic](https://github.com/NaturalIntelligence/Stubmatic) : A stub server to mock behaviour of HTTP(s) / REST / SOAP services. Stubbing redis is on the way.
161-
- [compare js](https://github.com/NaturalIntelligence/comparejs) : compare the features of JS code, libraries, and NPM repos.
162-
- [fast-lorem-ipsum](https://github.com/amitguptagwl/fast-lorem-ipsum) : Generate lorem ipsum words, sentences, paragraph very quickly.
184+
- [fast-lorem-ipsum](https://github.com/amitguptagwl/fast-lorem-ipsum) : Generate lorem ipsum words, sentences, paragraph very quickly.
163185

164186
### TODO
165187
* P2: validating XML stream data

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fast-xml-parser",
3-
"version": "2.9.5",
3+
"version": "3.0.0",
44
"description": "Validate XML or Parse XML to JS/JSON very fast without C/C++ based libraries",
55
"main": "./src/parser.js",
66
"scripts": {
@@ -33,7 +33,8 @@
3333
"transformer",
3434
"checker",
3535
"assert",
36-
"arrayMode"
36+
"arrayMode",
37+
"big"
3738
],
3839
"author": "Amit Gupta (https://github.com/amitguptagwl)",
3940
"contributors": [

static/img/fxp-validatorv3.png

11.2 KB
Loading
11.2 KB
Loading

0 commit comments

Comments
 (0)