Examples - AFS

AFS Integration Guide

Product
AFS
AFS_Version
7.7
Category
Reference Guide
  • Consider the following XML stream.

<nsname:widget xmlns:nsname="urn:example:namespace">
<nsname:name>SDK Widget</nsname:name>
<nsname:functions>
<nsname:function parameters="1">parse</nsname:function>
<nsname:function parameters="2">selectValue</nsname:function>
<nsname:function parameters="2">selectValues</nsname:function>
<nsname:function parameters="2">selectNodes</nsname:function>
</nsname:functions>
</nsname:widget>

  • XML SDK requires the used namespace to be set in the XML configuration as following:

{
...
"xml":
{
"namespaces": [
{
"name": "nsname",
"uri": "urn:example:namespace"
}
]
},
...
}

  • Assuming the XML stream (as string) is in the xmlStream variable, here is how to parse it.

var widgetDocument = AFSWidget.sdk.xml.parse(stream);

  • To get widget name:

console.log(AFSWidget.sdk.xml.selectValue(widgetDocument, '//nsname:name'));

  • The following code does the same thing:

console.log(AFSWidget.sdk.xml.parseAndSelectValue(stream, '//nsname:name'));

  • To retrieve the function names, use the following code:

var functions = AFSWidget.sdk.xml.selectValues(widgetDocument, '//nsname:function');
for (var i = 0; i < functions.length; i++)
{
var aFunction = functions[i];
console.log(AFSWidget.sdk.xml.selectValue(aFunction));
}

  • To display both functions and their parameters, selectNodes function must be used:

var functions = AFSWidget.sdk.xml.selectNodes(widgetDocument, '//nsname:function');
for (var i = 0; i < functions.length; i++)
{
var aFunction = functions[i];
var functionName = AFSWidget.sdk.xml.getNodeValue(aFunction);
var functionParametersCount = AFSWidget.sdk.xml.selectValue(aFunction, '@parameters');
console.log(functionName + ' takes ' + functionParametersCount + ' parameter(s)');
}

Note that getNodeValue is used to get the node string value.