Skip to content

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

Notifications You must be signed in to change notification settings

idris-maps/xml-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>'

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •