https://github.com/doga/xml
An XML parser and writer with namespace support. Packaged as a JavaScript ES6 module.
https://github.com/doga/xml
runnable-readme xml xml-parser xml-serializer
Last synced: about 1 year ago
JSON representation
An XML parser and writer with namespace support. Packaged as a JavaScript ES6 module.
- Host: GitHub
- URL: https://github.com/doga/xml
- Owner: doga
- License: apache-2.0
- Created: 2024-04-17T19:19:36.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-17T20:39:35.000Z (about 2 years ago)
- Last Synced: 2024-04-18T20:39:12.678Z (about 2 years ago)
- Topics: runnable-readme, xml, xml-parser, xml-serializer
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# XML parser and writer
An XML parser and writer with namespace support. Packaged as a JavaScript ES6 module.
## Usage examples
_Tip: Run the examples below by typing this in your terminal (requires Deno):_
```shell
deno run \
--allow-net --allow-run --allow-env --allow-read \
https://deno.land/x/mdrb@2.0.0/mod.ts \
--dax=false --mode=isolated \
https://raw.githubusercontent.com/doga/xml/master/README.md
```
Example: Parse and re-generate an XML string.
description = '''
Running this example is safe, it will not read or write anything to your filesystem.
'''
```javascript
import { Parser, Writer } from 'https://esm.sh/gh/doga/xml@1.0.0/mod.mjs';
const
xml =
`
`,
doc = new Parser(xml).document, // XmlDocument
// serialise the root element
xml2 = Writer.elementToString(doc.root);
console.info(xml2);
```
Sample output for the code above:
```text
```
Example: Build an XML document programmatically.
description = '''
Running this example is safe, it will not read or write anything to your filesystem.
'''
```javascript
import { Parser, Writer, XmlDocument, XmlElement, XmlComment } from 'https://esm.sh/gh/doga/xml@1.0.0/mod.mjs';
const
doc = new XmlDocument([
new XmlComment(
`A Qworum script that calls a login endpoint.
The Web application uses the Qworum browser extension
to run the script.`
),
new XmlElement(
'sequence', {xmlns: 'https://qworum.net/ns/v1/instruction/'},
[
new XmlElement(
'try', {},
[
new XmlElement('call', {href: '/login'}),
new XmlElement(
'catch', {faults: '["* cancelled"]'},
[new XmlElement('goto', {href: '/loginCancelled'})]
),
new XmlElement(
'catch', {faults: '["* failed"]'},
[new XmlElement('goto', {href: '/loginFailed'})]
),
]
),
new XmlElement('goto', {href: '/account'}),
]
)
]),
// serialise the root element
xml = Writer.elementToString(doc.root);
console.info(xml);
```
Sample output for the code above:
```text
```
∎