Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

saxen

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

saxen - npm Package Compare versions

Comparing version 4.0.0 to 4.0.1

2

package.json

@@ -16,3 +16,3 @@ {

],
"version": "4.0.0",
"version": "4.0.1",
"main": "./parser.js",

@@ -19,0 +19,0 @@ "bugs": {

@@ -23,5 +23,5 @@ # `/saxen/` parser <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/5f/Coat_of_arms_of_Saxony.svg/220px-Coat_of_arms_of_Saxony.svg.png" align="right" />

// enable namespace parsing
// element prefixes will automatically adjusted
// to the ones configured here
// enable namespace parsing: element prefixes will
// automatically adjusted to the ones configured here
// elements in other namespaces will still be processed
parser.ns({

@@ -32,3 +32,3 @@ 'http://foo': 'foo',

parser.on('openTag', function(elementName, getAttrs, decodeEntity, selfClosing, getContext) {
parser.on('openTag', function(elementName, attrGetter, decodeEntity, selfClosing, getContext) {

@@ -38,23 +38,64 @@ elementName;

var attrs = getAttrs();
var attrs = attrGetter();
// { 'bar:aa': 'A', ... }
});
parser.on('closeTag', function(elementName, decodeEntity, selfClosing, getContext) {
...
});
parser.parse('<blub xmlns="http://foo" xmlns:bar="http://bar" bar:aa="A" />');
```
parser.on('error', function(err, getContext) {
// rethrow or compensate for err
## Supported Hooks
We support the following parse hooks:
* `openTag(elementName, attrGetter, decodeEntities, selfClosing, contextGetter)`
* `closeTag(elementName, selfClosing, contextGetter)`
* `error(err, contextGetter)`
* `warn(warning, contextGetter)`
* `text(value, decodeEntities)`
* `cdata(value)`
* `comment(value, decodeEntities)`
* `attention(str, decodeEntities)`
* `question(str)`
In contrast to `error`, `warn` receives recoverable errors, such as malformed attributes.
## Namespace Handling
In namespace mode, the parser will adjust tag and attribute namespace prefixes before
passing the elements name to `openTag` or `closeTag`. To do that, you need to
configure default prefixes for wellknown namespaces:
```javascript
parser.ns({
'http://foo': 'foo',
'http://bar': 'bar'
});
```
parser.parse('<blub xmlns="http://foo" xmlns:bar="http://bar" bar:aa="A" />');
To skip the adjustment and still process namespace information:
```javascript
parser.ns();
```
## Non-Features
`/saxen/` lacks some features known in other XML parsers such as [sax-js](https://github.com/isaacs/sax-js):
* no support for parsing loose documents, such as arbitrary HTML snippets
* no support for text trimming
* no automatic entity decoding
* no automatic attribute parsing
...and that is ok ❤.
## Credits
This library builds on the awesome work done by [easysax](https://github.com/vflash/easysax) and adds anonymous namespace handling and an object mode.
We build on the awesome work done by [easysax](https://github.com/vflash/easysax).
It is named after [Sachsen](https://en.wikipedia.org/wiki/Saxony), a federal state of Germany. So geht sächsisch!
`/saxen/` is named after [Sachsen](https://en.wikipedia.org/wiki/Saxony), a federal state of Germany. So geht sächsisch!

@@ -61,0 +102,0 @@

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