Hi…
I have a requirement to find the maximum number of id in xml node..Y means If I want to add some more node then we need the maximum node then only we can update the next node by using code..then I goggled to find the method, mostly I found result would be loop process to find the maximum id,I think that one very lenthy process ,bcz xml has more nodes..its took waste time if we use for loop, one of my net friend gave me easiest process to find the maximum node. So I just thought share the code with you all………..
To remove particular code refer below link..
This is sample xml
<picture>
<image>
<id>1</id>
<name>raju</name
</image>
<image>
<id>2</id>
<name>karthi</name
</image>
<image>
<id>3</id>
<name>siva</name
</image>
Here we are going to find the maximum ‘id‘..Just follow the simple code I mention below….
Dim xmldoc As New XmlDocument
xmldoc.Load(xmlpath)
Dim max As String
Dim nav As XPathNavigator = xmldoc.CreateNavigator()
Dim sort As XPathExpression = nav.Compile("picture/image")
sort.AddSort("ID", XmlSortOrder.Descending, XmlCaseOrder.None, "", XmlDataType.Number)
max = nav.SelectSingleNode(sort).SelectSingleNode("ID").Value
The result maximum value could be ‘3’
max =3
I hope this will helpful those who seek to find max id in xml
Post your comments about the post……….
0 comments:
Post a Comment