xml-string
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

xml-string

Utility to create XML strings. Can be used to write any XML based files such as SVG, HTML or GPX.

Install

$ npm install xml-string

Usage

const xml = require('xml-string')

.create()

const svg = xml.create('svg')

.child()

Append a child element

const svg = xml.create('svg')
const g = svg.child('g')

.attr()

Add attributes

const svg = xml.create('svg')
const g = svg.child('g')
g.attr({ id: 'group' })

.data()

Add data

const svg = xml.create('svg')
const g = svg.child('g')
g.attr({ id: 'group' })
const text = g.child('text')
text.data('Hello world')

.outer()

Returns the XML string

const svg = xmlString.create('svg')
const g = svg.child('g')
g.attr({ id: 'group' })
const text = g.child('text')
text.data('Hello world')
 
console.log(svg.outer())
// returns
// '<svg><g id="group"><text>Hello world</text></g></svg>'

Aliases

  • .child() > .c()
  • .attr() > .a()
  • .data() > .d()

Example:

const svg = xml.create('svg')
const g = svg.c('g')
g.a({ id:'group' })
const text = g.c('text')
text.d('Hello world')
 
console.log(svg.outer())
// returns
// '<svg><g id="group"><text>Hello world</text></g></svg>'

Readme

Keywords

none

Package Sidebar

Install

npm i xml-string

Weekly Downloads

4

Version

2.0.2

License

ISC

Unpacked Size

12.7 kB

Total Files

10

Last publish

Collaborators

  • idris-maps