@infomaker/xml-handler
v0.7.1
Published
Infomaker JS module: Utility class for working with (reading, updating and creating) xml, nodes and attributes etc.
Downloads
48
Readme
XML handler client
A Client library simplifying working with XML.
Install
npm install -s @infomaker/xml-handler
Test
To run project test once use:
npm run test
or to enable auto-reload of test on save use:
npm run test-watch
Import
import XmlHandler from '@infomaker/xml-handler'
Publish a new release
Use GitFlow with master/develop/feature/release branches to handle new functionality and versions. When a new release-branch has been created run one of the following scripts to bump-version, create a tag and commit new changes.
npm run release:major
npm run release:minor
npm run release:hotfix
How to use
// Supports either xml-string or xml-document (will create own document if served with xml-string)
this.xmlHandler = new XmlHandler(this.conceptXml)
// Will transform xpath v. 2.0 wildcard namespace into 1.0 friendly value
// /*:conceptItem/*:itemMeta/*:links/*:link[@type='x-im/social+facebook'][@rel='irel:seeAlso']/@url
// /*[local-name(.) = 'conceptItem']/*[local-name(.) = 'itemMeta']/*[local-name(.) = 'links']/*[local-name(.) = 'link'][@type='x-im/social+twitter'][@rel='irel:seeAlso']/@url
const node = this.xmlHandler.getSafeNode(xpath)
const nodeValue = this.xmlHandler.getNodeValue(node)
// If the xpath doesent resolve to a node, create it like so:
if (!this.getSafeNode(xpath)) {
// Will create all nodes down to the last expression in the xpath
this.xmlHandler.createNodes(xpath)
this.xmlHandler.setNodeValue(node, value)
}
// Remove node
const isRemoved = this.xmlHandler.removeNode(node)
if (isRemoved) {
console.log('Node has been removed')
}