This tutorial will show you how to calculate average of data from XML using ASP.NET 2.0 and VB.

This tutorial will show you how to calculate average of data from XML using ASP.NET 2.0 and C#. The System.Xml.XPath namespace contains the classes that define a cursor model for navigating and editing XML information items as instances of the XPath 2.0 Data Model. XPath expressions as a string, or a compiled XPathExpression that return a W3C XPath type of boolean (System.Boolean), number (System.Double), string (System.String), or node set (System.Xml.XPath.XPathNodeIterator), can be passed to the Evaluate method. The Evaluate method takes the expression, evaluates it, and returns a typed result. This method could be used in a mathematical user defined method. For example, the following code calculates the total price of all item elements and div number of book in the current selection.

XPathNavigator class Provides a cursor model for navigating and editing XML data.
XPathDocument class Provides a fast, read-only cache for XML document processing using XSLT.
XPathNodeIterator class Provides an iterator over a selected set of nodes.

The following code of Button1_Click uses the Evaluate method with the average function.

The front end AverageXmlDataVB.aspx page looks something like this:

The flow for the code behind page is as follows.

Download Source Files