mirror of
https://github.com/apache/cordova-android.git
synced 2026-04-23 00:00:09 +08:00
CB-12621: reverted elementtree dep to 0.1.6
This commit is contained in:
+46
-53
@@ -9,7 +9,7 @@ the browser or other CommonJS implementations.
|
||||
|
||||
* A very simple tool to parse through an XML string.
|
||||
* A stepping stone to a streaming HTML parser.
|
||||
* A handy way to deal with RSS and other mostly-ok-but-kinda-broken XML
|
||||
* A handy way to deal with RSS and other mostly-ok-but-kinda-broken XML
|
||||
docs.
|
||||
|
||||
## What This Is (probably) Not
|
||||
@@ -23,7 +23,7 @@ the browser or other CommonJS implementations.
|
||||
implementations are in Java and do a lot more than this does.
|
||||
* An XML Validator - It does a little validation when in strict mode, but
|
||||
not much.
|
||||
* A Schema-Aware XSD Thing - Schemas are an exercise in fetishistic
|
||||
* A Schema-Aware XSD Thing - Schemas are an exercise in fetishistic
|
||||
masochism.
|
||||
* A DTD-aware Thing - Fetching DTDs is a much bigger job.
|
||||
|
||||
@@ -41,49 +41,48 @@ through unmolested.
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
var sax = require("./lib/sax"),
|
||||
strict = true, // set to false for html-mode
|
||||
parser = sax.parser(strict);
|
||||
var sax = require("./lib/sax"),
|
||||
strict = true, // set to false for html-mode
|
||||
parser = sax.parser(strict);
|
||||
|
||||
parser.onerror = function (e) {
|
||||
// an error happened.
|
||||
};
|
||||
parser.ontext = function (t) {
|
||||
// got some text. t is the string of text.
|
||||
};
|
||||
parser.onopentag = function (node) {
|
||||
// opened a tag. node has "name" and "attributes"
|
||||
};
|
||||
parser.onattribute = function (attr) {
|
||||
// an attribute. attr has "name" and "value"
|
||||
};
|
||||
parser.onend = function () {
|
||||
// parser stream is done, and ready to have more stuff written to it.
|
||||
};
|
||||
parser.onerror = function (e) {
|
||||
// an error happened.
|
||||
};
|
||||
parser.ontext = function (t) {
|
||||
// got some text. t is the string of text.
|
||||
};
|
||||
parser.onopentag = function (node) {
|
||||
// opened a tag. node has "name" and "attributes"
|
||||
};
|
||||
parser.onattribute = function (attr) {
|
||||
// an attribute. attr has "name" and "value"
|
||||
};
|
||||
parser.onend = function () {
|
||||
// parser stream is done, and ready to have more stuff written to it.
|
||||
};
|
||||
|
||||
parser.write('<xml>Hello, <who name="world">world</who>!</xml>').close();
|
||||
parser.write('<xml>Hello, <who name="world">world</who>!</xml>').close();
|
||||
|
||||
// stream usage
|
||||
// takes the same options as the parser
|
||||
var saxStream = require("sax").createStream(strict, options)
|
||||
saxStream.on("error", function (e) {
|
||||
// unhandled errors will throw, since this is a proper node
|
||||
// event emitter.
|
||||
console.error("error!", e)
|
||||
// clear the error
|
||||
this._parser.error = null
|
||||
this._parser.resume()
|
||||
})
|
||||
saxStream.on("opentag", function (node) {
|
||||
// same object as above
|
||||
})
|
||||
// pipe is supported, and it's readable/writable
|
||||
// same chunks coming in also go out.
|
||||
fs.createReadStream("file.xml")
|
||||
.pipe(saxStream)
|
||||
.pipe(fs.createReadStream("file-copy.xml"))
|
||||
|
||||
// stream usage
|
||||
// takes the same options as the parser
|
||||
var saxStream = require("sax").createStream(strict, options)
|
||||
saxStream.on("error", function (e) {
|
||||
// unhandled errors will throw, since this is a proper node
|
||||
// event emitter.
|
||||
console.error("error!", e)
|
||||
// clear the error
|
||||
this._parser.error = null
|
||||
this._parser.resume()
|
||||
})
|
||||
saxStream.on("opentag", function (node) {
|
||||
// same object as above
|
||||
})
|
||||
// pipe is supported, and it's readable/writable
|
||||
// same chunks coming in also go out.
|
||||
fs.createReadStream("file.xml")
|
||||
.pipe(saxStream)
|
||||
.pipe(fs.createWriteStream("file-copy.xml"))
|
||||
```
|
||||
|
||||
|
||||
## Arguments
|
||||
@@ -99,13 +98,9 @@ Settings supported:
|
||||
* `trim` - Boolean. Whether or not to trim text and comment nodes.
|
||||
* `normalize` - Boolean. If true, then turn any whitespace into a single
|
||||
space.
|
||||
* `lowercase` - Boolean. If true, then lowercase tag names and attribute names
|
||||
in loose mode, rather than uppercasing them.
|
||||
* `lowercasetags` - Boolean. If true, then lowercase tags in loose mode,
|
||||
rather than uppercasing them.
|
||||
* `xmlns` - Boolean. If true, then namespaces are supported.
|
||||
* `position` - Boolean. If false, then don't track line/col/position.
|
||||
* `strictEntities` - Boolean. If true, only parse [predefined XML
|
||||
entities](http://www.w3.org/TR/REC-xml/#sec-predefined-ent)
|
||||
(`&`, `'`, `>`, `<`, and `"`)
|
||||
|
||||
## Methods
|
||||
|
||||
@@ -169,7 +164,7 @@ might go away at some point. SAX isn't intended to be used to parse SGML,
|
||||
after all.
|
||||
|
||||
`opentag` - An opening tag. Argument: object with `name` and `attributes`.
|
||||
In non-strict mode, tag names are uppercased, unless the `lowercase`
|
||||
In non-strict mode, tag names are uppercased, unless the `lowercasetags`
|
||||
option is set. If the `xmlns` option is set, then it will contain
|
||||
namespace binding information on the `ns` member, and will have a
|
||||
`local`, `prefix`, and `uri` member.
|
||||
@@ -179,10 +174,8 @@ parent closes. In strict mode, well-formedness is enforced. Note that
|
||||
self-closing tags will have `closeTag` emitted immediately after `openTag`.
|
||||
Argument: tag name.
|
||||
|
||||
`attribute` - An attribute node. Argument: object with `name` and `value`.
|
||||
In non-strict mode, attribute names are uppercased, unless the `lowercase`
|
||||
option is set. If the `xmlns` option is set, it will also contains namespace
|
||||
information.
|
||||
`attribute` - An attribute node. Argument: object with `name` and `value`,
|
||||
and also namespace information if the `xmlns` option flag is set.
|
||||
|
||||
`comment` - A comment node. Argument: the string of the comment.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user