Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fabiospampinato/xml-simple-parser
A simple and tiny XML parser and stringifier.
https://github.com/fabiospampinato/xml-simple-parser
parser simple stringifier tiny xml
Last synced: 2 months ago
JSON representation
A simple and tiny XML parser and stringifier.
- Host: GitHub
- URL: https://github.com/fabiospampinato/xml-simple-parser
- Owner: fabiospampinato
- License: mit
- Created: 2023-09-03T15:47:55.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-09-24T16:28:51.000Z (over 1 year ago)
- Last Synced: 2024-11-12T17:51:33.261Z (3 months ago)
- Topics: parser, simple, stringifier, tiny, xml
- Language: TypeScript
- Homepage:
- Size: 7.81 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# XML Simple Parser
A simple and tiny XML parser and stringifier.
## Install
```sh
npm install --save xml-simple-parser
```## Usage
```ts
import XML from 'xml-simple-parser';// It can parse an XML string
const svg = `
`;
const ast = XML.parse ( svg );
// {
// "type": "root",
// "children": [
// {
// "type": "prolog",
// "attributes": {
// "version": "1.0",
// "encoding": "UTF-8",
// "standalone": "no"
// }
// },
// {
// "type": "doctype",
// "value": "svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"",
// "values": [
// "svg",
// "PUBLIC",
// "-//W3C//DTD SVG 1.1//EN",
// "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
// ]
// },
// {
// "type": "element",
// "name": "svg",
// "attributes": {
// "width": "100%",
// "height": "100%",
// "viewBox": "0 0 24 24",
// "version": "1.1",
// "xmlns": "http://www.w3.org/2000/svg",
// "xmlns:xlink": "http://www.w3.org/1999/xlink",
// "xml:space": "preserve"
// },
// "children": [
// {
// "type": "text",
// "value": "\n "
// },
// {
// "type": "element",
// "name": "rect",
// "attributes": {
// "x": "11",
// "y": "4",
// "width": "2",
// "height": "16"
// },
// "children": [],
// "void": true
// },
// {
// "type": "text",
// "value": "\n"
// }
// ],
// "void": false
// },
// {
// "type": "text",
// "value": "\n"
// }
// ]
// }// It can stringify an AST back to an equivalent XML string
const xml = XML.stringify ( ast );
//
//
//
//
//// It can check if a string is a valid XML string, according to this parser anyway
validate ( svg ); // => true
validate ( xml ); // => true
```## License
MIT © Fabio Spampinato