sax 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +55 -0
- package/README.md +42 -43
- package/lib/sax.js +462 -366
- package/package.json +8 -9
- package/LICENSE +0 -41
package/LICENSE.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Blue Oak Model License
|
|
2
|
+
|
|
3
|
+
Version 1.0.0
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
This license gives everyone as much permission to work with
|
|
8
|
+
this software as possible, while protecting contributors
|
|
9
|
+
from liability.
|
|
10
|
+
|
|
11
|
+
## Acceptance
|
|
12
|
+
|
|
13
|
+
In order to receive this license, you must agree to its
|
|
14
|
+
rules. The rules of this license are both obligations
|
|
15
|
+
under that agreement and conditions to your license.
|
|
16
|
+
You must not do anything with this software that triggers
|
|
17
|
+
a rule that you cannot or will not follow.
|
|
18
|
+
|
|
19
|
+
## Copyright
|
|
20
|
+
|
|
21
|
+
Each contributor licenses you to do everything with this
|
|
22
|
+
software that would otherwise infringe that contributor's
|
|
23
|
+
copyright in it.
|
|
24
|
+
|
|
25
|
+
## Notices
|
|
26
|
+
|
|
27
|
+
You must ensure that everyone who gets a copy of
|
|
28
|
+
any part of this software from you, with or without
|
|
29
|
+
changes, also gets the text of this license or a link to
|
|
30
|
+
<https://blueoakcouncil.org/license/1.0.0>.
|
|
31
|
+
|
|
32
|
+
## Excuse
|
|
33
|
+
|
|
34
|
+
If anyone notifies you in writing that you have not
|
|
35
|
+
complied with [Notices](#notices), you can keep your
|
|
36
|
+
license by taking all practical steps to comply within 30
|
|
37
|
+
days after the notice. If you do not do so, your license
|
|
38
|
+
ends immediately.
|
|
39
|
+
|
|
40
|
+
## Patent
|
|
41
|
+
|
|
42
|
+
Each contributor licenses you to do everything with this
|
|
43
|
+
software that would otherwise infringe any patent claims
|
|
44
|
+
they can license or become able to license.
|
|
45
|
+
|
|
46
|
+
## Reliability
|
|
47
|
+
|
|
48
|
+
No contributor can revoke this license.
|
|
49
|
+
|
|
50
|
+
## No Liability
|
|
51
|
+
|
|
52
|
+
***As far as the law allows, this software comes as is,
|
|
53
|
+
without any warranty or condition, and no contributor
|
|
54
|
+
will be liable to anyone for any damages related to this
|
|
55
|
+
software or this license, under any kind of legal claim.***
|
package/README.md
CHANGED
|
@@ -7,25 +7,25 @@ the browser or other CommonJS implementations.
|
|
|
7
7
|
|
|
8
8
|
## What This Is
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
- A very simple tool to parse through an XML string.
|
|
11
|
+
- A stepping stone to a streaming HTML parser.
|
|
12
|
+
- A handy way to deal with RSS and other mostly-ok-but-kinda-broken XML
|
|
13
13
|
docs.
|
|
14
14
|
|
|
15
15
|
## What This Is (probably) Not
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
- An HTML Parser - That's a fine goal, but this isn't it. It's just
|
|
18
18
|
XML.
|
|
19
|
-
|
|
19
|
+
- A DOM Builder - You can use it to build an object model out of XML,
|
|
20
20
|
but it doesn't do that out of the box.
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
- XSLT - No DOM = no querying.
|
|
22
|
+
- 100% Compliant with (some other SAX implementation) - Most SAX
|
|
23
23
|
implementations are in Java and do a lot more than this does.
|
|
24
|
-
|
|
24
|
+
- An XML Validator - It does a little validation when in strict mode, but
|
|
25
25
|
not much.
|
|
26
|
-
|
|
26
|
+
- A Schema-Aware XSD Thing - Schemas are an exercise in fetishistic
|
|
27
27
|
masochism.
|
|
28
|
-
|
|
28
|
+
- A DTD-aware Thing - Fetching DTDs is a much bigger job.
|
|
29
29
|
|
|
30
30
|
## Regarding `<!DOCTYPE`s and `<!ENTITY`s
|
|
31
31
|
|
|
@@ -42,71 +42,70 @@ through unmolested.
|
|
|
42
42
|
## Usage
|
|
43
43
|
|
|
44
44
|
```javascript
|
|
45
|
-
var sax = require(
|
|
45
|
+
var sax = require('./lib/sax'),
|
|
46
46
|
strict = true, // set to false for html-mode
|
|
47
|
-
parser = sax.parser(strict)
|
|
47
|
+
parser = sax.parser(strict)
|
|
48
48
|
|
|
49
49
|
parser.onerror = function (e) {
|
|
50
50
|
// an error happened.
|
|
51
|
-
}
|
|
51
|
+
}
|
|
52
52
|
parser.ontext = function (t) {
|
|
53
53
|
// got some text. t is the string of text.
|
|
54
|
-
}
|
|
54
|
+
}
|
|
55
55
|
parser.onopentag = function (node) {
|
|
56
56
|
// opened a tag. node has "name" and "attributes"
|
|
57
|
-
}
|
|
57
|
+
}
|
|
58
58
|
parser.onattribute = function (attr) {
|
|
59
59
|
// an attribute. attr has "name" and "value"
|
|
60
|
-
}
|
|
60
|
+
}
|
|
61
61
|
parser.onend = function () {
|
|
62
62
|
// parser stream is done, and ready to have more stuff written to it.
|
|
63
|
-
}
|
|
63
|
+
}
|
|
64
64
|
|
|
65
|
-
parser.write('<xml>Hello, <who name="world">world</who>!</xml>').close()
|
|
65
|
+
parser.write('<xml>Hello, <who name="world">world</who>!</xml>').close()
|
|
66
66
|
|
|
67
67
|
// stream usage
|
|
68
68
|
// takes the same options as the parser
|
|
69
|
-
var saxStream = require(
|
|
70
|
-
saxStream.on(
|
|
69
|
+
var saxStream = require('sax').createStream(strict, options)
|
|
70
|
+
saxStream.on('error', function (e) {
|
|
71
71
|
// unhandled errors will throw, since this is a proper node
|
|
72
72
|
// event emitter.
|
|
73
|
-
console.error(
|
|
73
|
+
console.error('error!', e)
|
|
74
74
|
// clear the error
|
|
75
75
|
this._parser.error = null
|
|
76
76
|
this._parser.resume()
|
|
77
77
|
})
|
|
78
|
-
saxStream.on(
|
|
78
|
+
saxStream.on('opentag', function (node) {
|
|
79
79
|
// same object as above
|
|
80
80
|
})
|
|
81
81
|
// pipe is supported, and it's readable/writable
|
|
82
82
|
// same chunks coming in also go out.
|
|
83
|
-
fs.createReadStream(
|
|
83
|
+
fs.createReadStream('file.xml')
|
|
84
84
|
.pipe(saxStream)
|
|
85
|
-
.pipe(fs.createWriteStream(
|
|
85
|
+
.pipe(fs.createWriteStream('file-copy.xml'))
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
|
|
89
88
|
## Arguments
|
|
90
89
|
|
|
91
|
-
Pass the following arguments to the parser function.
|
|
90
|
+
Pass the following arguments to the parser function. All are optional.
|
|
92
91
|
|
|
93
92
|
`strict` - Boolean. Whether or not to be a jerk. Default: `false`.
|
|
94
93
|
|
|
95
|
-
`opt` - Object bag of settings regarding string formatting.
|
|
94
|
+
`opt` - Object bag of settings regarding string formatting. All default to `false`.
|
|
96
95
|
|
|
97
96
|
Settings supported:
|
|
98
97
|
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
- `trim` - Boolean. Whether or not to trim text and comment nodes.
|
|
99
|
+
- `normalize` - Boolean. If true, then turn any whitespace into a single
|
|
101
100
|
space.
|
|
102
|
-
|
|
101
|
+
- `lowercase` - Boolean. If true, then lowercase tag names and attribute names
|
|
103
102
|
in loose mode, rather than uppercasing them.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
- `xmlns` - Boolean. If true, then namespaces are supported.
|
|
104
|
+
- `position` - Boolean. If false, then don't track line/col/position.
|
|
105
|
+
- `strictEntities` - Boolean. If true, only parse [predefined XML
|
|
107
106
|
entities](http://www.w3.org/TR/REC-xml/#sec-predefined-ent)
|
|
108
107
|
(`&`, `'`, `>`, `<`, and `"`)
|
|
109
|
-
|
|
108
|
+
- `unquotedAttributeValues` - Boolean. If true, then unquoted
|
|
110
109
|
attribute values are allowed. Defaults to `false` when `strict`
|
|
111
110
|
is true, `true` otherwise.
|
|
112
111
|
|
|
@@ -156,7 +155,7 @@ When using the stream interface, assign handlers using the EventEmitter
|
|
|
156
155
|
`error` - Indication that something bad happened. The error will be hanging
|
|
157
156
|
out on `parser.error`, and must be deleted before parsing can continue. By
|
|
158
157
|
listening to this event, you can keep an eye on that kind of stuff. Note:
|
|
159
|
-
this happens
|
|
158
|
+
this happens _much_ more in strict mode. Argument: instance of `Error`.
|
|
160
159
|
|
|
161
160
|
`text` - Text node. Argument: string of text.
|
|
162
161
|
|
|
@@ -172,13 +171,13 @@ might go away at some point. SAX isn't intended to be used to parse SGML,
|
|
|
172
171
|
after all.
|
|
173
172
|
|
|
174
173
|
`opentagstart` - Emitted immediately when the tag name is available,
|
|
175
|
-
but before any attributes are encountered.
|
|
176
|
-
`name` field and an empty `attributes` set.
|
|
174
|
+
but before any attributes are encountered. Argument: object with a
|
|
175
|
+
`name` field and an empty `attributes` set. Note that this is the
|
|
177
176
|
same object that will later be emitted in the `opentag` event.
|
|
178
177
|
|
|
179
178
|
`opentag` - An opening tag. Argument: object with `name` and `attributes`.
|
|
180
179
|
In non-strict mode, tag names are uppercased, unless the `lowercase`
|
|
181
|
-
option is set.
|
|
180
|
+
option is set. If the `xmlns` option is set, then it will contain
|
|
182
181
|
namespace binding information on the `ns` member, and will have a
|
|
183
182
|
`local`, `prefix`, and `uri` member.
|
|
184
183
|
|
|
@@ -187,12 +186,12 @@ parent closes. In strict mode, well-formedness is enforced. Note that
|
|
|
187
186
|
self-closing tags will have `closeTag` emitted immediately after `openTag`.
|
|
188
187
|
Argument: tag name.
|
|
189
188
|
|
|
190
|
-
`attribute` - An attribute node.
|
|
189
|
+
`attribute` - An attribute node. Argument: object with `name` and `value`.
|
|
191
190
|
In non-strict mode, attribute names are uppercased, unless the `lowercase`
|
|
192
|
-
option is set.
|
|
191
|
+
option is set. If the `xmlns` option is set, it will also contains namespace
|
|
193
192
|
information.
|
|
194
193
|
|
|
195
|
-
`comment` - A comment node.
|
|
194
|
+
`comment` - A comment node. Argument: the string of the comment.
|
|
196
195
|
|
|
197
196
|
`opencdata` - The opening tag of a `<![CDATA[` block.
|
|
198
197
|
|
|
@@ -220,9 +219,9 @@ If you pass `noscript: true`, then this behavior is suppressed.
|
|
|
220
219
|
|
|
221
220
|
## Reporting Problems
|
|
222
221
|
|
|
223
|
-
It's best to write a failing test if you find an issue.
|
|
222
|
+
It's best to write a failing test if you find an issue. I will always
|
|
224
223
|
accept pull requests with failing tests if they demonstrate intended
|
|
225
224
|
behavior, but it is very hard to figure out what issue you're describing
|
|
226
|
-
without a test.
|
|
225
|
+
without a test. Writing a test is also the best way for you yourself
|
|
227
226
|
to figure out if you really understand the issue you think you have with
|
|
228
227
|
sax-js.
|