AFS Integration Guide

Reference Guide
  • element parse(xmlString): Parses an XML string passed in the 'xmlString' parameter. Returns a DOM Element. If the document cannot be parsed, it returns undefined and the error is logged in the console.

  • string selectValue(element, xpathQuery): Executes an XPath query on the given element. Returns the element value (as string). If the xpathQuery matches several elements, the first one is returned. If the expression is invalid or matches no element, an empty string is returned and a log message is written in the console.

  • string parseAndSelectValue(xmlString, xpathQuery): Combines parse and selectValue functions.

  • string[] selectValues(element, xpathQuery): Executes an XPath query on the given element. Returns the list of the values of the matching nodes. Returns an empty string if the expression cannot be executed. In this case, the error messages is logged in the console.

  • string[] parseAndSelectValues(xmlString, xpathQuery): Combines parse and selectValues functions.

  • element[] selectNodes(element, xpathQuery): Does the same as selectValues but returns a list of elements instead of their string values.

  • element[] parseAndSelectNodes(xmlString, xpathQuery): Combines parse and selectNodes functions.

  • string getNodeValue(element): Returns the string value of an element. Returns an empty string if an error occurs. In this case, it is logged in the console.

  • string highlightMatchInNodeValue(element): Same as getNodeValue(element) but highlights matched client data (<afs:match>[...]</afs:match>) with <span class="match">[...]</span> in order to get them customizable through CSS.

  • string wrapInClientDataRootNode(xmlString): Sometimes the XML string is an XML fragment containing XML nodes but no root element. This utility wraps the xmlStrings in a <clientData> node to make the fragment XML valid, before using the other functions.