Socket
Socket
Sign inDemoInstall

sax

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sax - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

test/xml_entities.js

11

lib/sax.js

@@ -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" : "&"

2

package.json

@@ -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)
(`&amp;`, `&apos;`, `&gt;`, `&lt;`, and `&quot;`)

@@ -110,0 +114,0 @@ ## Methods

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc