var parseAttributes = require('./parse-attribs') var parseFromString = require('xml-parse-from-string') //In some cases element.attribute.nodeName can return //all lowercase values.. so we need to map them to the correct //case var NAME_MAP = { scaleh: 'scaleH', scalew: 'scaleW', stretchh: 'stretchH', lineheight: 'lineHeight', alphachnl: 'alphaChnl', redchnl: 'redChnl', greenchnl: 'greenChnl', bluechnl: 'blueChnl' } module.exports = function parse(data) { data = data.toString() var xmlRoot = parseFromString(data) var output = { pages: [], chars: [], kernings: [] } //get config settings ;['info', 'common'].forEach(function(key) { var element = xmlRoot.getElementsByTagName(key)[0] if (element) output[key] = parseAttributes(getAttribs(element)) }) //get page info var pageRoot = xmlRoot.getElementsByTagName('pages')[0] if (!pageRoot) throw new Error('malformed file -- no element') var pages = pageRoot.getElementsByTagName('page') for (var i=0; i