Comparing version 1.0.0 to 1.1.0
@@ -62,3 +62,4 @@ // wrapper for non-node envs | ||
parser.state = S.BEGIN | ||
parser.ENTITIES = Object.create(sax.ENTITIES) | ||
parser.strictEntities = parser.opt.strictEntities | ||
parser.ENTITIES = parser.strictEntities ? Object.create(sax.XML_ENTITIES) : Object.create(sax.ENTITIES) | ||
parser.attribList = [] | ||
@@ -349,2 +350,10 @@ | ||
sax.XML_ENTITIES = | ||
{ "amp" : "&" | ||
, "gt" : ">" | ||
, "lt" : "<" | ||
, "quot" : "\"" | ||
, "apos" : "'" | ||
} | ||
sax.ENTITIES = | ||
@@ -351,0 +360,0 @@ { "amp" : "&" |
@@ -5,3 +5,3 @@ { | ||
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"main": "lib/sax.js", | ||
@@ -8,0 +8,0 @@ "license": "BSD", |
@@ -12,3 +12,3 @@ # sax js | ||
* 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. | ||
@@ -27,3 +27,3 @@ | ||
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. | ||
@@ -45,44 +45,45 @@ * A DTD-aware Thing - Fetching DTDs is a much bigger job. | ||
## Usage | ||
```Javascript | ||
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. | ||
}; | ||
```javascript | ||
var sax = require("./lib/sax"), | ||
strict = true, // set to false for html-mode | ||
parser = sax.parser(strict); | ||
parser.write('<xml>Hello, <who name="world">world</who>!</xml>').close(); | ||
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. | ||
}; | ||
// 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")) | ||
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.createWriteStream("file-copy.xml")) | ||
``` | ||
@@ -108,2 +109,5 @@ | ||
* `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 `"`) | ||
@@ -110,0 +114,0 @@ ## Methods |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
475455
66
2670
221
65