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

xml-parser-xo

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml-parser-xo - npm Package Compare versions

Comparing version 4.0.0 to 4.0.1

4

dist/esnext/index.d.ts

@@ -53,2 +53,6 @@ export declare type XmlParserOptions = {

};
export declare class ParsingError extends Error {
readonly cause: string;
constructor(message: string, cause: string);
}
/**

@@ -55,0 +59,0 @@ * Parse the given XML string into an object.

28

dist/esnext/index.js

@@ -0,1 +1,7 @@

export class ParsingError extends Error {
constructor(message, cause) {
super(message);
this.cause = cause;
}
}
let parsingState;

@@ -27,4 +33,7 @@ function nextChild() {

if (!documentRootNode) {
throw new Error('Failed to parse XML');
throw new ParsingError('Failed to parse XML', 'Root Element not found');
}
if (parsingState.xml.length !== 0) {
throw new ParsingError('Failed to parse XML', 'Not Well-Formed XML');
}
return {

@@ -93,14 +102,12 @@ declaration: declaration ? declaration.node : null,

match(/\??>/);
if (!excluded) {
// children
let child = nextChild();
while (child) {
if (!child.excluded) {
node.children.push(child.node);
}
child = nextChild();
// children
let child = nextChild();
while (child) {
if (!child.excluded) {
node.children.push(child.node);
}
child = nextChild();
}
// closing
match(/^<\/[\w-:.]+>/);
match(/^<\/\s*[\w-:.\u00C0-\u00FF]+>/);
return {

@@ -213,2 +220,3 @@ excluded,

}
module.exports = parseXml;
export default parseXml;

@@ -53,2 +53,6 @@ export declare type XmlParserOptions = {

};
export declare class ParsingError extends Error {
readonly cause: string;
constructor(message: string, cause: string);
}
/**

@@ -55,0 +59,0 @@ * Parse the given XML string into an object.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParsingError = void 0;
class ParsingError extends Error {
constructor(message, cause) {
super(message);
this.cause = cause;
}
}
exports.ParsingError = ParsingError;
let parsingState;

@@ -29,4 +37,7 @@ function nextChild() {

if (!documentRootNode) {
throw new Error('Failed to parse XML');
throw new ParsingError('Failed to parse XML', 'Root Element not found');
}
if (parsingState.xml.length !== 0) {
throw new ParsingError('Failed to parse XML', 'Not Well-Formed XML');
}
return {

@@ -95,14 +106,12 @@ declaration: declaration ? declaration.node : null,

match(/\??>/);
if (!excluded) {
// children
let child = nextChild();
while (child) {
if (!child.excluded) {
node.children.push(child.node);
}
child = nextChild();
// children
let child = nextChild();
while (child) {
if (!child.excluded) {
node.children.push(child.node);
}
child = nextChild();
}
// closing
match(/^<\/[\w-:.]+>/);
match(/^<\/\s*[\w-:.\u00C0-\u00FF]+>/);
return {

@@ -215,2 +224,3 @@ excluded,

}
module.exports = parseXml;
exports.default = parseXml;
{
"name": "xml-parser-xo",
"version": "4.0.0",
"version": "4.0.1",
"repository": "github:chrisbottin/xml-parser",

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

# xml-parser-xo
XML parser based on [xml-parser](https://www.npmjs.com/package/xml-parser).
An XML parser based on [xml-parser](https://www.npmjs.com/package/xml-parser).

@@ -16,6 +16,6 @@ [![Build Status](https://github.com/chrisbottin/xml-parser/actions/workflows/ci.yml/badge.svg)](https://github.com/chrisbottin/xml-parser/actions/workflows/ci.yml) [![npm version](https://img.shields.io/npm/v/xml-parser-xo.svg)](https://npmjs.org/package/xml-parser-xo)

JavaScript:
### Usage:
```js
var parse = require('xml-parser-xo');
import xmlParser from 'xml-parser-xo';

@@ -28,6 +28,6 @@ var xml = `<?xml version="1.0" encoding="utf-8"?>

console.log(parse(xml));
xmlParser(xml);
```
Output:
### Output:

@@ -66,4 +66,55 @@ ```json

# License
## Options
MIT
- `filter` (`function(node) => boolean`) Function to filter out unwanted nodes by returning `false`.
### Usage:
```js
import xmlParser from 'xml-parser-xo';
const xml = `<?xml version="1.0" encoding="utf-8"?>
<!-- Load the stylesheet -->
<?xml-stylesheet href="foo.xsl" type="text/xsl" ?>
<!DOCTYPE foo SYSTEM "foo.dtd">
<foo><![CDATA[some text]]> content</foo>`;
xmlParser(xml, {
filter: (node) => {
return node.type === 'Element' || node.type === 'Text';
}
});
```
### Output:
```json
{
"declaration": {
"type": "ProcessingInstruction",
"attributes": {"version": "1.0", "encoding": "utf-8"}
},
"root": {
"type": "Element",
"name": "foo",
"attributes": {},
"children": [
{"type": "Text", "content": " content"}
]
},
"children": [
{
"type": "Element",
"name": "foo",
"attributes": {},
"children": [
{"type": "Text", "content": " content"}
]
}
]
}
```
## License
MIT
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