DBLookup with JavaScript and XPath

DBLookup with JavaScript and XPath

This code is my own version of a JavaScript DBLookup using XPath. It works with both categorized and non-categorized views. It is for Internet Explorer only.

function dbLookup(dblDatabase,
dblView,dblKey,dblColumn,dblLimit){
//David Schmidt, 2005-10-27
try{
 dblColumn=dblColumn-1;
 var xmldoc=new ActiveXObject
("MSXML2.DOMDocument");
 xmldoc.async=false;
 docLimit=(dblLimit!="")?dblLimit:"-1";
 xmldoc.load("/"+dblDatabase+"/"+dblView+"
?readviewentries&expandview&PreFormat&count="
+docLimit);
 if(xmldoc.parseError.errorCode!=0){
  var xmlerror=xmldoc.parseError;
  errorstr="XSL error\n\nError code: "
+xmlerror.errorCode+"\nReason: "+
xmlerror.reason+"\nLine: "+xmlerror.line+"\nLine position: 
"+xmlerror.linepos+"\nsrcText: "
+xmlerror.srcText+"\nUrl:"+xmlerror.url+"\nFile position: 
"+xmlerror.filepos;
  alert(errorstr);
  return "error";
 }else{
  columnNode=xmldoc.documentElement.selectNodes
("/viewentries/viewentry/entrydata[@columnnumber='0' 
and .='"+dblKey+"']");
  dblArray=new Array();
  if(columnNode.length>0){
   if(columnNode.item(0).getAttribute("category")){
     NodePosition=
columnNode.item(0).parentNode.getAttribute("position");
     xmldoc.setProperty("SelectionLanguage", "XPath");
     xpathquery=
"/viewentries/viewentry/entrydata[starts-with
(../@position,'"+NodePosition+".') and 
@columnnumber="+dblColumn+"]";
     categoryNode= 
xmldoc.documentElement.selectNodes(xpathquery);

    Requires Free Membership to View

    Register today to access targeted resources from our editorial writers and independent industry experts focused on Lotus Domino, Notes, Workplace and other related technologies.

    By submitting your registration information to SearchDomino.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchDomino.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

for(x=0;x<categoryNode.length;x++){ dblArray[x]=categoryNode[x].childNodes(0).text; } }else{ for(x=0;x<columnNode.length;x++){ dblArray[x]= columnNode[x].parentNode.childNodes(dblColumn).text; } } } return dblArray; } }catch(e){ var errName=e.name; var errNumber=e.number & 0xFFFF; var errDescription=e.description; errMessage=e+"\n\nName: "+errName+"\nNumber: " +errNumber+"\nDescription: "+errDescription; alert(errMessage); return error; } }

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member David Schmidt. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our bimonthly tip contest and you could win a prize and a spot in our Hall of Fame.

This was first published in October 2005

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.