XML : Node JS, ForEach,waiting for value to be set and then returning

I have some node that needs to parses some XML, looks at some attributes of a particular node and finds the one that starts with a particular string.

i.e.

1) get XML children (with xmldoc)

2) do any of the attributes on each node start with prefix

3) if they do return the value after prefix

4) break and return it from the function

The hackiness i have so far is below. It seems to run as async not sync. Any ideas?

  function getAttributeClassification(prefix, xmlO) {          var toReturn = undefined;          var res = Promise.all(xmlO.childrenNamed("childNode").map(function (child) {                  if (child.attr.uri.indexOf(prefix) > -1 ) {                          toReturn = child.attr.uri.split(prefix)[1];                  }                  return new Promise(function () {toReturn;} );          })).then(function (data){                  console.log("result; "+data);                  return new Promise(function(){});          });  }    

No comments:

Post a Comment