Distinct Values in XML with .Net


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Distinct Values in XML with .Net

  1. #1
    Join Date
    Jul 2004
    Posts
    11

    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

  2. #2
    Join Date
    May 2009
    Location
    United Kingdom
    Posts
    49
    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

  1. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 07:46 AM
  2. .Net Xml vs MS Xml 4.0
    By Ara Ashikian in forum XML
    Replies: 2
    Last Post: 03-27-2002, 03:47 PM
  3. YAG's public status report - March 7, 2002
    By Seth Grossman [MSFT] in forum vb.announcements
    Replies: 1
    Last Post: 03-13-2002, 08:32 PM
  4. yag's status report - Feb 7, 2002
    By Yair Alan Griver [MS] in forum .NET
    Replies: 4
    Last Post: 02-11-2002, 10:35 AM
  5. Replies: 0
    Last Post: 11-19-2001, 06: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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center