How to install third party libraries?

You can use the third party libraries in Smartface.

XML Parsing in Smartface

If you want to work with XML data, you can use the third party xml parser library.

Example library : https://github.com/NaturalIntelligence/fast-xml-parser

Install library on Smartface :

(cd ~/workspace/scripts/node_modules && npm install fast-xml-parser)

XML Parse Example :

var fastXmlParser = require('fast-xml-parser');
var xmlData = "<bookstore><book>" +
"<title>Everyday Italian</title>" +
"<author>Giada De Laurentiis</author>" +
"<year>2005</year>" +
"</book></bookstore>";
var JsonResult = fastXmlParser.parse(xmlData);
console.log("JSON Data : " + JSON.stringify(JsonResult))
// when a tag has attributes
var options = {
attrPrefix: "@_",
attrNodeName: false,
textNodeName: "#text",
ignoreNonTextNodeAttr: true,
ignoreTextNodeAttr: true,
ignoreNameSpace: true,
ignoreRootElement: false,
textNodeConversion: true,
textAttrConversion: false,
arrayMode: false
};
if (fastXmlParser.validate(xmlData) === true) { //optional
JsonResult = fastXmlParser.parse(xmlData, options);
console.log("JSON Data : " + JSON.stringify(JsonResult))
}
//Intermediate obj
var tObj = fastXmlParser.getTraversalObj(xmlData, options);
JsonResult = fastXmlParser.convertToJson(tObj);
console.log("JSON Data : " + JSON.stringify(JsonResult))

JSON Parsing in Smartface

var JsonResult = JSON.parse(data); // data is string.
console.log("JSON Data : " + JSON.stringify(JsonResult))