0.1.1 • Published 4 years ago

parse-flat-xml-dict-pmb v0.1.1

Weekly downloads
4
License
ISC
Repository
github
Last release
4 years ago

parse-flat-xml-dict-pmb

Parse an XML fragment that contains only a very trivial key-value structure.

API

This module exports one function:

readDict(xmlFrag, opt)

Given an XML fragment xmlFrag of suitable structure, return a dictionary object mapping elements' names to their text content.

A suitable fragment must consist of only whitespace and/or simple elements. Simple elements have just a name and optional text content. This means they can not have: a namespace, attributes, child elements.

opts is an optional options object that supports these keys:

  • combineTexts: A function that merges non-first occurrences of an element name. It will be called with arguments (oldValue, newText, key, dict) and is expected to return the combined new value. If false-y (default), an error is thrown on encounter of a duplicate key.

Known issues

  • Needs more/better tests and docs.

 

License

ISC