xml2js 0.1.1
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.
- checksums.yaml +7 -0
- data/.rspec_status +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +41 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/xml2js.rb +5 -0
- data/lib/xml2js/node_modules/sax/LICENSE +41 -0
- data/lib/xml2js/node_modules/sax/README.md +225 -0
- data/lib/xml2js/node_modules/sax/lib/sax.js +1565 -0
- data/lib/xml2js/node_modules/sax/package.json +61 -0
- data/lib/xml2js/node_modules/xml2js/LICENSE +19 -0
- data/lib/xml2js/node_modules/xml2js/README.md +406 -0
- data/lib/xml2js/node_modules/xml2js/lib/bom.js +12 -0
- data/lib/xml2js/node_modules/xml2js/lib/builder.js +127 -0
- data/lib/xml2js/node_modules/xml2js/lib/defaults.js +72 -0
- data/lib/xml2js/node_modules/xml2js/lib/parser.js +357 -0
- data/lib/xml2js/node_modules/xml2js/lib/processors.js +34 -0
- data/lib/xml2js/node_modules/xml2js/lib/xml2js.js +37 -0
- data/lib/xml2js/node_modules/xml2js/package.json +280 -0
- data/lib/xml2js/node_modules/xmlbuilder/.npmignore +5 -0
- data/lib/xml2js/node_modules/xmlbuilder/CHANGELOG.md +423 -0
- data/lib/xml2js/node_modules/xmlbuilder/LICENSE +21 -0
- data/lib/xml2js/node_modules/xmlbuilder/README.md +85 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/Utility.js +73 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLAttribute.js +31 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLCData.js +32 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLComment.js +32 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDTDAttList.js +50 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDTDElement.js +35 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDTDEntity.js +56 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDTDNotation.js +37 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDeclaration.js +40 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDocType.js +107 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDocument.js +48 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLDocumentCB.js +402 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLElement.js +111 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLNode.js +432 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLProcessingInstruction.js +35 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLRaw.js +32 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLStreamWriter.js +279 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLStringWriter.js +334 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLStringifier.js +163 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLText.js +32 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/XMLWriterBase.js +90 -0
- data/lib/xml2js/node_modules/xmlbuilder/lib/index.js +53 -0
- data/lib/xml2js/node_modules/xmlbuilder/package.json +65 -0
- data/lib/xml2js/package-lock.json +25 -0
- data/lib/xml2js/parser.js +33 -0
- data/lib/xml2js/parser.rb +31 -0
- data/lib/xml2js/version.rb +3 -0
- data/xml2js.gemspec +30 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e195e07e5aa8075c525c58e830e969019e90f2163f5574457918ae3ea7b97d3b
|
4
|
+
data.tar.gz: bea2031ee7ac0fb5892a4208909eabdeb8dc78334d522a34cd2e02aaaf392e11
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b8c9bc37d1034879001690a8cf7847cfdea3b3e1eb8050be33cab4f3bf2c8de01f00eacbf3a785b30848901de6c732bf2ceedfe06196bce692c6180322a390fe
|
7
|
+
data.tar.gz: bdacc7363ad4adf89fed1998bb0c32d06a1b6d47ffa2ca9b0ab54c9f912c7c03ec33951234839b7735348cd2bb6ca687016edde10661c4bc700d71ce264e7a45
|
data/.rspec_status
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at micharch54@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
xml2js (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.2)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
method_source (0.9.2)
|
12
|
+
pry (0.12.2)
|
13
|
+
coderay (~> 1.1.0)
|
14
|
+
method_source (~> 0.9.0)
|
15
|
+
rake (10.5.0)
|
16
|
+
rspec (3.8.0)
|
17
|
+
rspec-core (~> 3.8.0)
|
18
|
+
rspec-expectations (~> 3.8.0)
|
19
|
+
rspec-mocks (~> 3.8.0)
|
20
|
+
rspec-core (3.8.0)
|
21
|
+
rspec-support (~> 3.8.0)
|
22
|
+
rspec-expectations (3.8.2)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.8.0)
|
25
|
+
rspec-mocks (3.8.0)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.8.0)
|
28
|
+
rspec-support (3.8.0)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
bundler (~> 2.0)
|
35
|
+
pry
|
36
|
+
rake (~> 10.0)
|
37
|
+
rspec (~> 3.0)
|
38
|
+
xml2js!
|
39
|
+
|
40
|
+
BUNDLED WITH
|
41
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Michael
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Xml2js
|
2
|
+
|
3
|
+
Xml2js is intended to be a wrapper around the excellent xml2js node package. While at my previous company we ran into many instances where current ruby xml parsers just simply did not capture everything in the long xml files that we used. The node version did. So to solve for this in our Ruby apps we can actually use Xml2js.
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'xml2js'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install xml2js
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
require 'xml2js'
|
24
|
+
xml_hash = Xml2js::Parser.parse(xml_data)
|
25
|
+
|
26
|
+
```
|
27
|
+
|
28
|
+
## Development
|
29
|
+
|
30
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
31
|
+
|
32
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Neener54/xml2js. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
+
|
42
|
+
## Code of Conduct
|
43
|
+
|
44
|
+
Everyone interacting in the Xml2js project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Neener54/xml2js/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "xml2js"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/xml2js.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
The ISC License
|
2
|
+
|
3
|
+
Copyright (c) Isaac Z. Schlueter and Contributors
|
4
|
+
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
15
|
+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
16
|
+
|
17
|
+
====
|
18
|
+
|
19
|
+
`String.fromCodePoint` by Mathias Bynens used according to terms of MIT
|
20
|
+
License, as follows:
|
21
|
+
|
22
|
+
Copyright Mathias Bynens <https://mathiasbynens.be/>
|
23
|
+
|
24
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
25
|
+
a copy of this software and associated documentation files (the
|
26
|
+
"Software"), to deal in the Software without restriction, including
|
27
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
28
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
29
|
+
permit persons to whom the Software is furnished to do so, subject to
|
30
|
+
the following conditions:
|
31
|
+
|
32
|
+
The above copyright notice and this permission notice shall be
|
33
|
+
included in all copies or substantial portions of the Software.
|
34
|
+
|
35
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
36
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
37
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
38
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
39
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
40
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
41
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,225 @@
|
|
1
|
+
# sax js
|
2
|
+
|
3
|
+
A sax-style parser for XML and HTML.
|
4
|
+
|
5
|
+
Designed with [node](http://nodejs.org/) in mind, but should work fine in
|
6
|
+
the browser or other CommonJS implementations.
|
7
|
+
|
8
|
+
## What This Is
|
9
|
+
|
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
|
+
docs.
|
14
|
+
|
15
|
+
## What This Is (probably) Not
|
16
|
+
|
17
|
+
* An HTML Parser - That's a fine goal, but this isn't it. It's just
|
18
|
+
XML.
|
19
|
+
* A DOM Builder - You can use it to build an object model out of XML,
|
20
|
+
but it doesn't do that out of the box.
|
21
|
+
* XSLT - No DOM = no querying.
|
22
|
+
* 100% Compliant with (some other SAX implementation) - Most SAX
|
23
|
+
implementations are in Java and do a lot more than this does.
|
24
|
+
* An XML Validator - It does a little validation when in strict mode, but
|
25
|
+
not much.
|
26
|
+
* A Schema-Aware XSD Thing - Schemas are an exercise in fetishistic
|
27
|
+
masochism.
|
28
|
+
* A DTD-aware Thing - Fetching DTDs is a much bigger job.
|
29
|
+
|
30
|
+
## Regarding `<!DOCTYPE`s and `<!ENTITY`s
|
31
|
+
|
32
|
+
The parser will handle the basic XML entities in text nodes and attribute
|
33
|
+
values: `& < > ' "`. It's possible to define additional
|
34
|
+
entities in XML by putting them in the DTD. This parser doesn't do anything
|
35
|
+
with that. If you want to listen to the `ondoctype` event, and then fetch
|
36
|
+
the doctypes, and read the entities and add them to `parser.ENTITIES`, then
|
37
|
+
be my guest.
|
38
|
+
|
39
|
+
Unknown entities will fail in strict mode, and in loose mode, will pass
|
40
|
+
through unmolested.
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
```javascript
|
45
|
+
var sax = require("./lib/sax"),
|
46
|
+
strict = true, // set to false for html-mode
|
47
|
+
parser = sax.parser(strict);
|
48
|
+
|
49
|
+
parser.onerror = function (e) {
|
50
|
+
// an error happened.
|
51
|
+
};
|
52
|
+
parser.ontext = function (t) {
|
53
|
+
// got some text. t is the string of text.
|
54
|
+
};
|
55
|
+
parser.onopentag = function (node) {
|
56
|
+
// opened a tag. node has "name" and "attributes"
|
57
|
+
};
|
58
|
+
parser.onattribute = function (attr) {
|
59
|
+
// an attribute. attr has "name" and "value"
|
60
|
+
};
|
61
|
+
parser.onend = function () {
|
62
|
+
// parser stream is done, and ready to have more stuff written to it.
|
63
|
+
};
|
64
|
+
|
65
|
+
parser.write('<xml>Hello, <who name="world">world</who>!</xml>').close();
|
66
|
+
|
67
|
+
// stream usage
|
68
|
+
// takes the same options as the parser
|
69
|
+
var saxStream = require("sax").createStream(strict, options)
|
70
|
+
saxStream.on("error", function (e) {
|
71
|
+
// unhandled errors will throw, since this is a proper node
|
72
|
+
// event emitter.
|
73
|
+
console.error("error!", e)
|
74
|
+
// clear the error
|
75
|
+
this._parser.error = null
|
76
|
+
this._parser.resume()
|
77
|
+
})
|
78
|
+
saxStream.on("opentag", function (node) {
|
79
|
+
// same object as above
|
80
|
+
})
|
81
|
+
// pipe is supported, and it's readable/writable
|
82
|
+
// same chunks coming in also go out.
|
83
|
+
fs.createReadStream("file.xml")
|
84
|
+
.pipe(saxStream)
|
85
|
+
.pipe(fs.createWriteStream("file-copy.xml"))
|
86
|
+
```
|
87
|
+
|
88
|
+
|
89
|
+
## Arguments
|
90
|
+
|
91
|
+
Pass the following arguments to the parser function. All are optional.
|
92
|
+
|
93
|
+
`strict` - Boolean. Whether or not to be a jerk. Default: `false`.
|
94
|
+
|
95
|
+
`opt` - Object bag of settings regarding string formatting. All default to `false`.
|
96
|
+
|
97
|
+
Settings supported:
|
98
|
+
|
99
|
+
* `trim` - Boolean. Whether or not to trim text and comment nodes.
|
100
|
+
* `normalize` - Boolean. If true, then turn any whitespace into a single
|
101
|
+
space.
|
102
|
+
* `lowercase` - Boolean. If true, then lowercase tag names and attribute names
|
103
|
+
in loose mode, rather than uppercasing them.
|
104
|
+
* `xmlns` - Boolean. If true, then namespaces are supported.
|
105
|
+
* `position` - Boolean. If false, then don't track line/col/position.
|
106
|
+
* `strictEntities` - Boolean. If true, only parse [predefined XML
|
107
|
+
entities](http://www.w3.org/TR/REC-xml/#sec-predefined-ent)
|
108
|
+
(`&`, `'`, `>`, `<`, and `"`)
|
109
|
+
|
110
|
+
## Methods
|
111
|
+
|
112
|
+
`write` - Write bytes onto the stream. You don't have to do this all at
|
113
|
+
once. You can keep writing as much as you want.
|
114
|
+
|
115
|
+
`close` - Close the stream. Once closed, no more data may be written until
|
116
|
+
it is done processing the buffer, which is signaled by the `end` event.
|
117
|
+
|
118
|
+
`resume` - To gracefully handle errors, assign a listener to the `error`
|
119
|
+
event. Then, when the error is taken care of, you can call `resume` to
|
120
|
+
continue parsing. Otherwise, the parser will not continue while in an error
|
121
|
+
state.
|
122
|
+
|
123
|
+
## Members
|
124
|
+
|
125
|
+
At all times, the parser object will have the following members:
|
126
|
+
|
127
|
+
`line`, `column`, `position` - Indications of the position in the XML
|
128
|
+
document where the parser currently is looking.
|
129
|
+
|
130
|
+
`startTagPosition` - Indicates the position where the current tag starts.
|
131
|
+
|
132
|
+
`closed` - Boolean indicating whether or not the parser can be written to.
|
133
|
+
If it's `true`, then wait for the `ready` event to write again.
|
134
|
+
|
135
|
+
`strict` - Boolean indicating whether or not the parser is a jerk.
|
136
|
+
|
137
|
+
`opt` - Any options passed into the constructor.
|
138
|
+
|
139
|
+
`tag` - The current tag being dealt with.
|
140
|
+
|
141
|
+
And a bunch of other stuff that you probably shouldn't touch.
|
142
|
+
|
143
|
+
## Events
|
144
|
+
|
145
|
+
All events emit with a single argument. To listen to an event, assign a
|
146
|
+
function to `on<eventname>`. Functions get executed in the this-context of
|
147
|
+
the parser object. The list of supported events are also in the exported
|
148
|
+
`EVENTS` array.
|
149
|
+
|
150
|
+
When using the stream interface, assign handlers using the EventEmitter
|
151
|
+
`on` function in the normal fashion.
|
152
|
+
|
153
|
+
`error` - Indication that something bad happened. The error will be hanging
|
154
|
+
out on `parser.error`, and must be deleted before parsing can continue. By
|
155
|
+
listening to this event, you can keep an eye on that kind of stuff. Note:
|
156
|
+
this happens *much* more in strict mode. Argument: instance of `Error`.
|
157
|
+
|
158
|
+
`text` - Text node. Argument: string of text.
|
159
|
+
|
160
|
+
`doctype` - The `<!DOCTYPE` declaration. Argument: doctype string.
|
161
|
+
|
162
|
+
`processinginstruction` - Stuff like `<?xml foo="blerg" ?>`. Argument:
|
163
|
+
object with `name` and `body` members. Attributes are not parsed, as
|
164
|
+
processing instructions have implementation dependent semantics.
|
165
|
+
|
166
|
+
`sgmldeclaration` - Random SGML declarations. Stuff like `<!ENTITY p>`
|
167
|
+
would trigger this kind of event. This is a weird thing to support, so it
|
168
|
+
might go away at some point. SAX isn't intended to be used to parse SGML,
|
169
|
+
after all.
|
170
|
+
|
171
|
+
`opentagstart` - Emitted immediately when the tag name is available,
|
172
|
+
but before any attributes are encountered. Argument: object with a
|
173
|
+
`name` field and an empty `attributes` set. Note that this is the
|
174
|
+
same object that will later be emitted in the `opentag` event.
|
175
|
+
|
176
|
+
`opentag` - An opening tag. Argument: object with `name` and `attributes`.
|
177
|
+
In non-strict mode, tag names are uppercased, unless the `lowercase`
|
178
|
+
option is set. If the `xmlns` option is set, then it will contain
|
179
|
+
namespace binding information on the `ns` member, and will have a
|
180
|
+
`local`, `prefix`, and `uri` member.
|
181
|
+
|
182
|
+
`closetag` - A closing tag. In loose mode, tags are auto-closed if their
|
183
|
+
parent closes. In strict mode, well-formedness is enforced. Note that
|
184
|
+
self-closing tags will have `closeTag` emitted immediately after `openTag`.
|
185
|
+
Argument: tag name.
|
186
|
+
|
187
|
+
`attribute` - An attribute node. Argument: object with `name` and `value`.
|
188
|
+
In non-strict mode, attribute names are uppercased, unless the `lowercase`
|
189
|
+
option is set. If the `xmlns` option is set, it will also contains namespace
|
190
|
+
information.
|
191
|
+
|
192
|
+
`comment` - A comment node. Argument: the string of the comment.
|
193
|
+
|
194
|
+
`opencdata` - The opening tag of a `<![CDATA[` block.
|
195
|
+
|
196
|
+
`cdata` - The text of a `<![CDATA[` block. Since `<![CDATA[` blocks can get
|
197
|
+
quite large, this event may fire multiple times for a single block, if it
|
198
|
+
is broken up into multiple `write()`s. Argument: the string of random
|
199
|
+
character data.
|
200
|
+
|
201
|
+
`closecdata` - The closing tag (`]]>`) of a `<![CDATA[` block.
|
202
|
+
|
203
|
+
`opennamespace` - If the `xmlns` option is set, then this event will
|
204
|
+
signal the start of a new namespace binding.
|
205
|
+
|
206
|
+
`closenamespace` - If the `xmlns` option is set, then this event will
|
207
|
+
signal the end of a namespace binding.
|
208
|
+
|
209
|
+
`end` - Indication that the closed stream has ended.
|
210
|
+
|
211
|
+
`ready` - Indication that the stream has reset, and is ready to be written
|
212
|
+
to.
|
213
|
+
|
214
|
+
`noscript` - In non-strict mode, `<script>` tags trigger a `"script"`
|
215
|
+
event, and their contents are not checked for special xml characters.
|
216
|
+
If you pass `noscript: true`, then this behavior is suppressed.
|
217
|
+
|
218
|
+
## Reporting Problems
|
219
|
+
|
220
|
+
It's best to write a failing test if you find an issue. I will always
|
221
|
+
accept pull requests with failing tests if they demonstrate intended
|
222
|
+
behavior, but it is very hard to figure out what issue you're describing
|
223
|
+
without a test. Writing a test is also the best way for you yourself
|
224
|
+
to figure out if you really understand the issue you think you have with
|
225
|
+
sax-js.
|