Skip to content

mk-pmb/parse-flat-xml-dict-pmb-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published