An open API service indexing awesome lists of open source software.

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.

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

```