Distinct Values in XML with .Net
I am developing an application on .Net and wish to use XML for drop down list. I do not want the drop down list to have repetitive data. For e.g If my drop down list has Countries and their States as L1 and L2 table respectively, I do not want L1 to repeat name of the country (e.g India) 30+ times as those many states of India get listed on L2.
Sub fillLevel2(ByVal level1 As String, ByVal dd As DropDownList)
Dim strXML As String = Server.MapPath("~") & "\xmlFiles\LOV.xml"
Dim xdoc1 As New XPathDocument(strXML)
Dim xNav1 As XPathNavigator = xdoc1.CreateNavigator()
Dim xNodeIterator1 As XPathNodeIterator
Dim xPathExpr1 As XPathExpression = xNav1.Compile("(//Table[LOVLevel1 ='" & level1 & "'])/LOVLevel2")
xPathExpr1.AddSort(".", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Text)
xNodeIterator1 = xNav1.Select(xPathExpr1)
dd.Items.Insert(0, New ListItem("Select Level2", ""))
Thanks in advance for the assistance
I have not come across anything in .NET that will allow a distinct select nodes. You're already using the XPathNavigator for the sort, which the XmlNode.SelectNodes() does not provide.
However, you could modify your XPath to prevent duplicates, I think that this would work for you:
Alternatively, it would required a second pass of the dd.Items collection to remove the duplicates.
//Table[LOVLevel1 ='" & level1 & "']/LOVLevel2[not(.=preceding-sibling::LOVLevel2)]
Last Post: 05-13-2005, 06:46 AM
By Ara Ashikian in forum XML
Last Post: 03-27-2002, 02:47 PM
By Seth Grossman [MSFT] in forum vb.announcements
Last Post: 03-13-2002, 07:32 PM
By Yair Alan Griver [MS] in forum .NET
Last Post: 02-11-2002, 09:35 AM
By AutomatedQA in forum dotnet.announcements
Last Post: 11-19-2001, 05:08 PM
Tags for this Thread
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL