Skip to main content link. Accesskey S
  • Help
  • HCL Logo
  • HCL Notes and Domino Application Development wiki
  • THIS WIKI IS READ-ONLY. Individual names altered for privacy purposes.
  • HCL Forums and Blogs
  • Home
  • Product Documentation
  • Community Articles
  • Learning Center
  • API Documentation
Search
Community Articles > Programming > LotusScript > Traversing XML result of AJAX request with JQuery
  • Share Show Menu▼
  • Subscribe Show Menu▼

Recent articles by this author

Traversing XML result of AJAX request with JQuery

When working with JQuery and Ajax, there is simply no simple good instructions on how to traverse the complete tree of an XML result of an Ajax call. This is how You do it.

A shortcut for get the number of rows used in Excelfile/Worksheet

When working with Excelfiles it is very common to know how many rows there is to process in the file so that You can inform the user in a progressbar or something. I've seen a numerous examples of simple looping through each row until the ActiveCell is a nullvalue (empty string). This is not very ...

How to create and send an email message containing an HTML body using an agent

To create an email that contains a HTML body is a quite simple process, but there is a lot to think about because of the variety of emailclients and their specific behaviour in how they implement the HTMLCSS specifications. I will here try to guide You through the complete steps needed to ...

Using XML response from Ajax call in Lotus Domino Web applications

There is a lot to say when it comes to AJAX! If You have read the article "Integrating Ajax into traditional IBM Lotus Domino Web applications" (http:www-10.lotus.comlddddwiki.nsfdxIntegratingAjaxintotraditionalIBMLotusDominoWebapplications) You will know how to use the Ajax response ...

HowTo: Create Bullet List in Word Document

I'm continuing the discussion on how to create a word document. Now it's time to understand how to format text in Word; This time I'll show how to write Bullet Lists into a word document. First, read up on how to create a word document here: ...
Community articleTraversing XML result of AJAX request with JQuery
Added by ~Richard Zekboosilyettu | Edited by ~Richard Zekboosilyettu on September 20, 2011 | Version 3
  • Actions Show Menu▼
expanded Abstract
collapsed Abstract
When working with JQuery and Ajax, there is simply no simple good instructions on how to traverse the complete tree of an XML result of an Ajax call. This is how You do it.
Tags: Javascript, JQuery, Ajax, XML, LotusScript
ShowTable of Contents
HideTable of Contents
  • 1 Traversing XML result of Ajax call
    • 1.1 The Agent
    • 1.2 The Form
    • 1.3 Explanation of the JavaScript
 

Traversing XML result of Ajax call

 When working with JQuery and Ajax, there is simply no simple good instructions on how to traverse the complete tree of an XML result of an Ajax call. This is how You do it.

The Agent

Let's create an agent that produces the XML result that we want to analyze. This is a dummy agent; the XML is static, but You could of course have it to retreive any data from any database and produce the correct XML of Your choise. 
 

Sub Initialize
	
	Dim result As String
	
	Print "Content-Type:text/xml;Char-Set:ISO-8859-15;"
	result = |<?xml version="1.0"?>| + Chr$(13)
	result = result + |<catalog>| + Chr$(13)
	result = result + |<album id="1"><name>My First Album</name>| + Chr$(13)
	result = result + |<artist>123</artist>| + Chr$(13)
	result = result + |</album>| + Chr$(13)
	result = result + |<album id="2"><name>Second time around</name>| + Chr$(13)
	result = result + |<artist>123</artist>| + Chr$(13)
	result = result + |</album>| + Chr$(13)
	result = result + |</catalog>|
	
	Print result
	
End Sub
 
 
Make the agent trigger "Agent List selection" and run on Target "None". 
 
Time to create the form... 
 

The Form

 
 
 Now, create a form that has the following HTMLHead content:
 
 

"<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js\"></script>"+@NewLine +
"<script>" + @NewLine +
"var dbPath ='" + @WebDbName + "';" + @NewLine +
"</script>"
 
 
In the form, make passthrough HTML and write a button and a div: 
 
 
<input type="button" onclick="getDummyXML();" />
<br />
<div id="result">
</div>
 
 
In the JSHead, create function named "getDummyXML()": 
 
 
 function getDummyXML() {
	
	var dt = new Date();
	var agentURL = '/' + dbPath + '/(dummyXML)?OpenAgent&dt=' + dt;
	
	var bodyContent = '';
	bodyContent = $.ajax({ 
		url:agentURL,
      	success: function(xml){ 
      	showResult(xml);
      	}
   		} 
	).responseXml;
}
 
 
The JQuery will make an Ajax call, and when it gets the result, it will call a function named "showResult()". So, we need to create that function as well in the JSHead: 
 
 
function showResult(xml) {


	var fld = $('#result');
	var result = '';
	result = '<h3>This is the result of xml: </h3><p>';
	
	var nodes = $(xml).find('catalog').children();
	$(nodes).each(function() { 
		$(this).children().each( function() { 
			result += 'NodeName = ' + $(this).get(0).nodeName + '<br />';
			result += 'NodeValue = ' + $(this).text() + '<br />';
                        result += 'Attribute = ' + $(this).parent().attr("id") + '<br />'; 
			result += '<br />';
		})
	});
	result += '</p>';
	fld.html(result);
}
 
 
 
Thats it... Now some explanation... 
 

Explanation of the JavaScript

 
 
In the first line, we assign a JavaScript variable to hold the div-tag. $('#result') is the same as doing the classic: document.getElementById('result'); .
 
We will assign a JavaScript variable to hold all the child-nodes of the "Catalog"-root node: 
var nodes = $(xml).find('catalog').children(); 
 
Next lines are doing the actual traversing - for each child node of the Catalog-node, get the actual node-name and the value of the node and everything is stored in the "result"-variable. 
To get the attribute "id" that is stored in the "album"-node, we need to go up one level with the .parent() selector and then get the attribute with .attr('id') selector. 
 
The last line is putting all the result into the innerHTML of the DIV-tag and thats it... 
  

  • Actions Show Menu▼


expanded Attachments (0)
collapsed Attachments (0)
Edit the article to add or modify attachments.
expanded Versions (3)
collapsed Versions (3)
Version Comparison     
VersionDateChanged by              Summary of changes
This version (3)Sep 20, 2011, 8:53:08 AM~Richard Zekboosilyettu  Added the result for the id attribute of the album node.
2Sep 20, 2011, 8:46:02 AM~Vanessa Preponelyynds  Minor change
1Sep 20, 2011, 8:44:42 AM~Vanessa Preponelyynds  
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedAbout
  • HCL Software
  • HCL Digital Solutions community
  • HCL Software support
  • BlogsDigital Solutions blog
  • Community LinkHCL Software forums and blogs
  • About HCL
  • Privacy
  • Accessibility