XPath helper function

Keith Berard shows a small ACL helper function that makes it easy to use XPath expressions from Java or C# Last Updated: 2006-06-18

One useful thing that came out of AUGI was a simple helper method if you're used to dealing with Nodes instead. This assumes you're primarily working in a language other than ACL. First, define a routine in ACL:

=ACL= package xpath_utils; function oid_xpath_nodeset_str(srcOid, xpath) {  local array[]; oid_xpath_nodeset(srcOid, array, xpath); return join(array, "|"); }

=Then, in the other language=

JAVA
public static Node[] selectNodes(Node srcNode, String xpath) { String oidStr = ((ANode)srcNode).getFirstOID; String oidStrList; try { oidStrList = Acl.func("xpath_utils::oid_xpath_nodeset_str", oidStr, xpath); } catch (AclException e) { Application.alert(e.getLocalizedMessage); return null; }  if (oidStrList.length > 0) { String[] oids = oidStrList.split("|"); Node[] results = new Node[oids.length]; for (int i = 0 ; i < oids.length ; i++) { Node curNode = Acl.getDOMOID(oids[i]); results[i] = curNode; }    return results; }  return null; }

C#
public Epic.IDOMNode[] SelectNodes(Epic.IDOMNode srcNode, String xpath) {   String oidStr = ((Epic.IDOMANode)srcNode).FirstOID; String oidStrList; try {       StringBuilder sb = new StringBuilder; sb.Append("xpath_utils::oid_xpath_nodeset_str(\"");       sb.Append(oidStr);        sb.Append("\",\"");        sb.Append(xpath);        sb.Append("\")"); string refString = sb.ToString; oidStrList = app.Acl.Eval(refString); }   catch (Exception e)    { return null; }   if (oidStrList.Length > 0) {       String[] oids = oidStrList.Split('|'); Epic.IDOMNode[] results = new Epic.IDOMNode[oids.Length]; for (int i = 0 ; i < oids.Length ; i++) {           Epic.IDOMNode curNode = app.Acl.DOMOID(oids[i]); results[i] = curNode; }       return results; }   return null; }

PS: Arbortext also mentioned that the version of XPath they were using is pretty old, so it may not support all XPath.