The syntax you use allows you to navigate through the nodes of a JSON object. But it looks like you are trying to find it as an XPath predicate. This will not work.
Using xml2js, you can get an array of time objects in your code using:
result.root.time
And then, a loop comparing the value of $.c as you reach the attributes. For example, the attribute of the second time element:
result.root.time[1].$.c
So, the data you need to compare with your field. When you find out which element of the time array it is in, you get a title (actually a singleton array containing the header), like this:
var resultArr = []; for(var i = 0; i < result.root.time.length; i++) { if (result.root.time[i].$.c == timetag) { resultArr = result.root.time[i].title; break; } }
What you can send to your socket:
io.sockets.emit('subs', { subs: resultArr[0] });
Solution Using JSONPath
If you don't want to implement a loop in JavaScript to compare attribute values, you can use JSONPath. This syntax is not as good as XPath, but it works. You will need to get it through NPM and require:
var jsonpath = require('JSONPath');
And then you can get a title with this expression:
var expression = "$.root.time[?(@.$.c == '00:00:01')].title[0]";
[..] is a predicate ? should run a script with the expression, @. is access to the attribute (which is represented in the xml2js object as $.c . line with your timetag variable.
To search, use:
var resultArr = jsonpath.eval(result, expression);
An array containing the desired text will be returned. Then you can send it wherever you want:
io.sockets.emit('subs', { subs: resultArr[0] });
You can learn more about JSONPath here: http://goessner.net/articles/JsonPath/