-
Distinct Values in XML with .Net
Hi,
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)
While xNodeIterator1.MoveNext()
dd.Items.Add(xNodeIterator1.Current.Value)
End While
dd.Items.Insert(0, New ListItem("Select Level2", ""))
End Sub
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:
Code:
//Table[LOVLevel1 ='" & level1 & "']/LOVLevel2[not(.=preceding-sibling::LOVLevel2)]
Alternatively, it would required a second pass of the dd.Items collection to remove the duplicates.
Similar Threads
-
Replies: 1
Last Post: 05-13-2005, 06:46 AM
-
By Ara Ashikian in forum XML
Replies: 2
Last Post: 03-27-2002, 02:47 PM
-
By Seth Grossman [MSFT] in forum vb.announcements
Replies: 1
Last Post: 03-13-2002, 07:32 PM
-
By Yair Alan Griver [MS] in forum .NET
Replies: 4
Last Post: 02-11-2002, 09:35 AM
-
By AutomatedQA in forum dotnet.announcements
Replies: 0
Last Post: 11-19-2001, 05:08 PM
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|