Skip to content

Commit 53fde91

Browse files
committed
merge upstream
2 parents 4c35142 + c479b5e commit 53fde91

21 files changed

+943
-649
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### Checklist
2+
3+
* [ ] Are you running the latest version?
4+
* [ ] Include sample input XML
5+
* [ ] Include actual output
6+
* [ ] Include expected output
7+
* [ ] Did you try online [tool](https://naturalintelligence.github.io/fast-xml-parser/)?
8+
* [ ] Did you [star](https://github.com/NaturalIntelligence/fast-xml-parser/stargazers) the repository for further updates? ;)
9+

.npmignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ spec
77
.codeclimate.yml
88
todo
99
index.html
10-
static/*
10+
static/*
11+
.github
12+
lib

BACKERS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

CHANGELOG.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
2.9.3 / 2018-01-26
2+
* Merge pull request: Correctly remove CRLF line breaks
3+
* Enable to parse attribute in online editor
4+
* Fix testing demo app test
5+
* Describe parsing options
6+
* Add options for online demo
7+
2.9.2 / 2018-01-18
8+
* Remove check if tag starting with "XML"
9+
* Fix: when there are spaces before / after CDATA
10+
11+
2.9.1 / 2018-01-16
12+
* Fix: newline should be replaced with single space
13+
* Fix: for single and multiline comments
14+
* validate xml with CDATA
15+
* Fix: the issue when there is no space between 2 attributes
16+
* Fix: https://github.com/NaturalIntelligence/fast-xml-parser/issues/33: when there is newline char in attr val, it doesn't parse
17+
* Merge pull request: fix ignoreNamespace
18+
* fix: don't wrap attributes if only namespace attrs
19+
* fix: use portfinder for run tests, update deps
20+
* fix: don't treat namespaces as attributes when ignoreNamespace enabled
21+
22+
2.9.0 / 2018-01-10
23+
* Rewrite the validator to handle large files.
24+
Ignore DOCTYPE validation.
25+
* Fix: When attribute value has equal sign
26+
27+
2.8.3 / 2017-12-15
28+
* Fix: when a tag has value along with subtags
29+
30+
2.8.2 / 2017-12-04
31+
* Fix value parsing for IE
32+
33+
2.8.1 / 2017-12-01
34+
* fix: validator should return false instead of err when invalid XML
35+
36+
2.8.0 / 2017-11-29
37+
* Add CLI option to ignore value conversion
38+
* Fix variable name when filename is given on CLI
39+
* Update CLI help text
40+
* Merge pull request: xml2js: Accept standard input
41+
* Test Node 8
42+
* Update dependencies
43+
* Bundle readToEnd
44+
* Add ability to read from standard input
45+
46+
2.7.4 / 2017-09-22
47+
* Merge pull request: Allow wrap attributes with subobject to compatible with other parsers output
48+
49+
2.7.3 / 2017-08-02
50+
* fix: handle CDATA with regx
51+
52+
2.7.2 / 2017-07-30
53+
* Change travis config for yarn caching
54+
* fix validator: when tag property is same as array property
55+
* Merge pull request: Failing test case in validator for valid SVG
56+
57+
2.7.1 / 2017-07-26
58+
* Fix: Handle val 0
59+
60+
2.7.0 / 2017-07-25
61+
* Fix test for arrayMode
62+
* Merge pull request: Add arrayMode option to parse any nodes as arrays
63+
64+
2.6.0 / 2017-07-14
65+
* code improvement
66+
* Add unit tests for value conversion for attr
67+
* Merge pull request: option of an attribute value conversion to a number (textAttrConversion) the same way as the textNodeConversion option does. Default value is false.
68+
69+
2.5.1 / 2017-07-01
70+
* Fix XML element name pattern
71+
* Fix XML element name pattern while parsing
72+
* Fix validation for xml tag element
73+
74+
2.5.0 / 2017-06-25
75+
* Improve Validator performance
76+
* update attr matching regex
77+
* Add perf tests
78+
* Improve atrr regex to handle all cases
79+
80+
2.4.4 / 2017-06-08
81+
* Bug fix: when an attribute has single or double quote in value
82+
83+
2.4.3 / 2017-06-05
84+
* Bug fix: when multiple CDATA tags are given
85+
* Merge pull request: add option "textNodeConversion"
86+
* add option "textNodeConversion"
87+
88+
2.4.1 / 2017-04-14
89+
* fix tests
90+
* Bug fix: preserve initial space of node value
91+
* Handle CDATA
92+
93+
2.3.1 / 2017-03-15
94+
* Bug fix: when single self closing tag
95+
* Merge pull request: fix .codeclimate.yml
96+
* Update .codeclimate.yml - Fixed config so it does not error anymore.
97+
* Update .codeclimate.yml
98+
99+
2.3.0 / 2017-02-26
100+
* Code improvement
101+
* add bithound config
102+
* Update usage
103+
* Update travis to generate bundle js before running tests
104+
* 1.Browserify, 2. add more tests for validator
105+
* Add validator
106+
* Fix CLI default parameter bug
107+
108+
2.2.1 / 2017-02-05
109+
* Bug fix: CLI default option

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,24 @@ You can use this library online (press try me button above), or as command from
77
* Or you can transform/covert/parse XML data to JS/JSON object.
88
* Or you can transform the XML in traversable JS object which can later be converted to JS/JSON object.
99

10-
[![Code Climate](https://codeclimate.com/github/NaturalIntelligence/fast-xml-parser/badges/gpa.svg)](https://codeclimate.com/github/NaturalIntelligence/fast-xml-parser) [<img src="https://www.paypalobjects.com/webstatic/en_US/btn/btn_donate_92x26.png" alt="Stubmatic donate button"/>](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KQJAX48SPUKNC) <a href="https://liberapay.com/amitgupta/donate"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg"></a> [![Known Vulnerabilities](https://snyk.io/test/github/naturalintelligence/fast-xml-parser/badge.svg)](https://snyk.io/test/github/naturalintelligence/fast-xml-parser) [![Travis ci Build Status](https://travis-ci.org/NaturalIntelligence/fast-xml-parser.svg?branch=master)](https://travis-ci.org/NaturalIntelligence/fast-xml-parser) [![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/)
10+
[![Code Climate](https://codeclimate.com/github/NaturalIntelligence/fast-xml-parser/badges/gpa.svg)](https://codeclimate.com/github/NaturalIntelligence/fast-xml-parser)
11+
[<img src="https://www.paypalobjects.com/webstatic/en_US/btn/btn_donate_92x26.png" alt="Stubmatic donate button"/>](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KQJAX48SPUKNC)
12+
<a href="https://liberapay.com/amitgupta/donate"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg"></a>
13+
[![Known Vulnerabilities](https://snyk.io/test/github/naturalintelligence/fast-xml-parser/badge.svg)](https://snyk.io/test/github/naturalintelligence/fast-xml-parser)
14+
[![NPM quality][quality-image]][quality-url]
15+
[![Travis ci Build Status](https://travis-ci.org/NaturalIntelligence/fast-xml-parser.svg?branch=master)](https://travis-ci.org/NaturalIntelligence/fast-xml-parser)
16+
[![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)
17+
[<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/)
1118
[![bitHound Dev Dependencies](https://www.bithound.io/github/NaturalIntelligence/fast-xml-parser/badges/devDependencies.svg)](https://www.bithound.io/github/NaturalIntelligence/fast-xml-parser/master/dependencies/npm)
12-
[![bitHound Overall Score](https://www.bithound.io/github/NaturalIntelligence/fast-xml-parser/badges/score.svg)](https://www.bithound.io/github/NaturalIntelligence/fast-xml-parser) [![NPM total downloads](https://img.shields.io/npm/dt/fast-xml-parser.svg)](https://npm.im/fast-xml-parser)
19+
[![bitHound Overall Score](https://www.bithound.io/github/NaturalIntelligence/fast-xml-parser/badges/score.svg)](https://www.bithound.io/github/NaturalIntelligence/fast-xml-parser)
20+
[![NPM total downloads](https://img.shields.io/npm/dt/fast-xml-parser.svg)](https://npm.im/fast-xml-parser)
21+
22+
[quality-image]: http://npm.packagequality.com/shield/fast-xml-parser.svg?style=flat-square
23+
[quality-url]: http://packagequality.com/#?package=fast-xml-parser
24+
25+
<a href="https://opencollective.com/fast-xml-parser/donate" target="_blank">
26+
<img src="https://opencollective.com/fast-xml-parser/donate/button@2x.png?color=blue" width=300 />
27+
</a>
1328

1429
### How to use
1530
**Installation**
@@ -48,6 +63,17 @@ var jsonObj = fastXmlParser.convertToJson(tObj);
4863

4964
```
5065

66+
67+
* **attrNodeName**: (Valid name) Group all the attributes as properties of given name.
68+
* **ignoreNonTextNodeAttr** : Ignore attributes of non-text node.
69+
* **ignoreTextNodeAttr** : Ignore attributes for text node
70+
* **ignoreNameSpace** : Remove namespace string from tag and attribute names.
71+
* **ignoreRootElement** : Remove root element from parsed JSON.
72+
* **textNodeConversion** : Parse the value of text node to float or integer.
73+
* **textAttrConversion** : Parse the value of an attribute to float or integer.
74+
* **arrayMode** : Put the value(s) of a tag or attribute in an array.
75+
76+
5177
To use from command line
5278
```bash
5379
$xml2js [-ns|-a|-c] <filename> [-o outputfile.json]
@@ -66,6 +92,8 @@ var isValid = parser.validate(xmlData);
6692
var jsonObj = parser.parse(xmlData);
6793
```
6894

95+
Or use directly from [CDN](https://cdnjs.com/libraries/fast-xml-parser)
96+
6997
## Comparision
7098
I decided to created this library when I couldn't find any library which can convert XML data to json without any callback and which is not based on any C/C++ library.
7199

benchmark/perfTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var Benchmark = require('benchmark');
22
var suite = new Benchmark.Suite("XML Parser benchmark");
33

4-
var parser = require("../bin/parser");
4+
var parser = require("../src/parser");
55

66
var fs = require("fs");
77
var path = require("path");

cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var fs = require('fs');
44
var path = require('path');
55
var parser = require('./lib/parser');
6-
var readToEnd = require('./lib/read').readToEnd;
6+
var readToEnd = require('./src/read').readToEnd;
77

88

99
if(process.argv[2] === "--help" || process.argv[2] === "-h"){

index.html

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title>Fast XMl Parser</title>
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1">
7-
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css">
7+
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css">
88
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
99
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css">
1010
<link rel="stylesheet" href="static/css/jquery-confirm.min.css">
@@ -22,10 +22,8 @@
2222

2323
<div class="container">
2424
<a href="https://github.com/NaturalIntelligence/fast-xml-parser"><img class="bring-up" style="position: absolute; top: 0; left: 0; border: 0;" src="https://camo.githubusercontent.com/121cd7cbdc3e4855075ea8b558508b91ac463ac2/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f6c6566745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_left_green_007200.png"></a>
25-
<h3 style="color:white;">Fast XML Parser</h3>
26-
<div style="margin-top: -12px; margin-bottom: 10px;">
27-
<span id="version" style="font-size: xx-small"></span>&nbsp;-&nbsp;<span id="timestamp" style="font-size: xx-small"></span>
28-
</div>
25+
<h1 style="color:white;">Fast XML Parser</h1>
26+
2927
<div class="row">
3028
<div class="col-md-6">
3129
<div class="form-group">
@@ -75,19 +73,22 @@ <h3 style="color:white;">Fast XML Parser</h3>
7573
</any_name>
7674
</textarea>
7775
</div>
78-
79-
<div class="input-group">
80-
<span class="input-group-btn">
76+
<div class="row">
77+
<div class="col-md-8" style=" color: white;">
78+
<input type="checkbox" id="attrNodeName"> Group all the attributes as properties of given name. <br>
79+
<input type="checkbox" id="ignoreTextNodeAttr" checked="true"> Ignore attributes from parsing <br>
80+
<input type="checkbox" id="ignoreNameSpace"> Remove namespace string from tag and attribute names. <br>
81+
<input type="checkbox" id="ignoreRootElement"> Remove root element from parsed JSON. <br>
82+
<input type="checkbox" id="textNodeConversion" checked="true"> Parse the value of text node to float or integer.<br>
83+
<input type="checkbox" id="textAttrConversion"> Parse the value of an attribute to float or integer.<br>
84+
<input type="checkbox" id="arrayMode"> Put the value(s) of a tag or attribute in an array. <br>
8185
<button id="submit" class="btn btn-primary" type="button">Parse to JSON</button>
82-
</span>
83-
84-
<span class="input-group-btn">
86+
</div>
87+
<div class="col-md-4">
8588
<button id="validate" class="btn btn-primary" type="button">Validate XML</button>
86-
</span>
89+
</div>
8790
</div>
8891

89-
<br/>
90-
9192
</div>
9293
<div class="col-md-6">
9394
<textarea id="result" rows="30" class="form-control" placeholder="Output"></textarea>
@@ -100,16 +101,16 @@ <h3 style="color:white;">Fast XML Parser</h3>
100101
setTimeout(function(){
101102
$.dialog({
102103
title: '',
103-
content: '<p>If you like my work, plz give me a '
104+
content: '<p style="color:black">If you like my work, plz give me a '
104105
+ '<a href="https://github.com/NaturalIntelligence/fast-xml-parser/stargazers"><i class="fa fa2x fa-star animated infinite tada"></i></a>'
105106
+ '.</p>'
106107

107108
});
108109
}, 5000)
109110
$('#submit').on('click', function() {
110111
$('#result').empty();
111-
112-
var jsonData = parser.parse($('#txtXml').val());
112+
113+
var jsonData = parser.parse($('#txtXml').val(),buildParsingConfig());
113114
$('#result').text(JSON.stringify(jsonData,null,4));
114115
});
115116

@@ -123,6 +124,23 @@ <h3 style="color:white;">Fast XML Parser</h3>
123124
$('#result').text(e);
124125
}
125126
});
127+
128+
function buildParsingConfig(){
129+
var config = {
130+
attrPrefix : "",
131+
attrNodeName: $("#attrNodeName").prop("checked") ? "@" : false,
132+
textNodeName : "#text",
133+
ignoreNonTextNodeAttr : $("#ignoreTextNodeAttr").prop("checked"),
134+
ignoreTextNodeAttr : $("#ignoreTextNodeAttr").prop("checked"),
135+
ignoreNameSpace : $("#ignoreNameSpace").prop("checked"),
136+
ignoreRootElement : $("#ignoreRootElement").prop("checked"),
137+
textNodeConversion : $("#textNodeConversion").prop("checked"),
138+
textAttrConversion : $("#textAttrConversion").prop("checked"),
139+
arrayMode : $("#arrayMode").prop("checked")
140+
};
141+
142+
return config;
143+
}
126144
});
127145
</script>
128146

0 commit comments

Comments
 (0)