sum(/Database/it...@code='4000']/Item)
On Nov 9, 12:10 am, Faraz Azhar <[email protected]> wrote: > Hello > > First of all, Im sorry if im posting this question in an inappropriate > group. Secondly, Im working on VB.NET using XPath queries. > > My problem is that I have a XML file which holds my inventory and > sales data. I need to use SUM formulas of XPath language. > Here is my XML file:http://dotnetdevelopment.pastebin.com/m2fec233e > > In that file, I want to know the sum of the amounts under any Item > Code. For example, if I want to know the sum of all the amounts under > Code 4003, I will use the following code: > > Dim xmlDB As New Xml.XmlDocument > Dim xmlNav As Xml.XPath.XPathNavigator > ' > xmlDB.Load("C:\test\ff.xml") > xmlNav = xmlDB.CreateNavigator() > MsgBox(xmlNav.Evaluate("sum(//Database/Item/*...@code=4003])")) > > The above code returns 433.32, this is correct. But if I want to know > the sum of all the child nodes under Code 4000, how do I do it ? I use > the same XPath query above but type 4000 in the query. It returns > zero. I want to be able to sum up all the child nodes under the code > 4000. This XML file is a sample file only. There many be many levels > of nested nodes in my project. So my query should return the sum of > all the child nodes, standing at any particular Code. > > Any help people? > Faraz Azhar
