exports.convert = function(data, callback) { if (data && typeof(data) === 'string') { callback(null, exports.flat(xml.parseString(data).childs[0].childs)); } else { callback(new Error('input must be string')); } };
module.exports = function (grunt, xmlDescriptorPath) { var info = { widgetBody: '' }; var pathModule = require('path'); var config = require('./config'); var getWidgetPrefs = require('./getWidgetPrefs'); var parseXML = require('node-xml-lite').parseString; var widgetFolder = pathModule.dirname(xmlDescriptorPath) + pathModule.sep; var destPath = grunt.config.get('destPath'); var setWidgetPrefs = require('./setWidgetPrefs'); var doc = parseXML( grunt.file.read(xmlDescriptorPath) ); doc.childs.forEach(function (child) { if (child.name === 'Content') { if (child.attrib && child.attrib.href) { info.widgetBody += grunt.file.read( widgetFolder + child.attrib.href); } else if (child.childs && child.childs[0]) { info.widgetBody += child.childs[0]; } else { grunt.log.errorlns('Widget Has no body, check .xml Content'); } } else if (child.name === 'ModulePrefs') { var prefs = getWidgetPrefs(grunt, child, widgetFolder ); Object.keys(prefs).forEach(function(key) { info[ key ] = prefs[ key ]; }); } }); return info; };
module.exports = function (grunt, descriptor, target) { target = target || 'make'; var config = require('./config'); var parseXML = require('node-xml-lite').parseString; var widgetFolder = grunt.config.get('widgetFolder'); var destPath = grunt.config.get('destPath'); var setWidgetPrefs = require('./setWidgetPrefs'); var doc = parseXML(descriptor), widgetConfig = grunt.config('widget'); doc.childs.forEach(function (child) { // skip text nodes if (typeof child != "object") return; if (child.name === 'Content') { widgetBody = grunt.config('widget.body') || ''; if (child.attrib && child.attrib.href) { grunt.config.set('widget.bodyHref', child.attrib.href); widgetBody += grunt.file.read( widgetFolder + child.attrib.href); } else if (child.childs && child.childs.length > 0) { //TODO investigate this case, what if there are many Content or href if (target == "make") { widgetBody += child.childs.join(""); } } else { grunt.log.errorlns('Widget Has no body, check .xml Content'); } grunt.config('widget.body', widgetBody); grunt.file.write( destPath + config.cacheBody, widgetBody ); grunt.task.run(['processhtml:'+target, 'writeBody']); } else if (child.name === 'ModulePrefs') { setWidgetPrefs(grunt, child); } }); };
function parseXml(b, options) { options = options || {} var pmap = options.propMap|| propMap var mmap = options.paramMap || paramMap var tree = xmllite.parseString(b) var xml = flattern(tree) return readable(xml, pmap, mmap) }
tree.fileFilter(/\.xml$/,function(next,done){ var props = this[key]; var contents = props.contents; try{ var x = xml.parseString(contents); props.setProp('data',x); }catch(err){ props.error = err; if(tree.devMode()=='development'){throw err;} } next(); });
request({uri:url, headers:headers}).then(function(res){ if (!/xhtml/i.test(res.headers['content-type'])) { fail('not xhtml, test is irrelevant'); }; var valid_xhtml = true; try{ xml_lite.parseString(res.body); }catch(e){ valid_xhtml = false; } ok(valid_xhtml); })
Translate.prototype.toObject = function(xmlData) { var obj = {}; try { var parsedData = xmlParser.parseString(this.keepEntities ? xmlData.replace(/&/g, "&") : xmlData); // first node must by 'translations' if ((parsedData) && (parsedData.name === "translations")) { for (var i=0; i<parsedData.childs.length; i++) { var entry = parsedData.childs[i]; // the child nodes must be 'translation' and must have an attribute 'id' if ((entry.name === "translation") && (entry.attrib) && (entry.attrib.id) && (entry.childs)) { obj[entry.attrib.id] = this.parsedDataToString(entry.childs); } } } } catch (e) { this.gruntInstance.log.error(e); throw e; } return obj; };