Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 14, 2012 03:44 PM by msmk
Nov 13, 2012 02:20 PM|LINK
From an XMLdatasource in alphabetical order, using VB, linq and asp.net.
Can someone give me an idea of how I can return results in a webform that only returns the employers where the first letter of the name Employer begins with A.
<?xml version="1.0" standalone="yes"?>
Nov 13, 2012 06:26 PM|LINK
You can change the "a" to be any input text using a variable passed in to the function.
Dim data As XmlDocument = New XmlDocument
Dim path As String = HttpContext.Current.Server.MapPath("yourPath")
Dim names As XmlNodeList = data.GetElementsByTagName("name")
Dim foundEmps As New List(Of String)
For Each name As xmlNode In names
Dim empName As String = name.Attributes("Employer").Value
If empName.ToLower().StartsWith("a") Then
Nov 14, 2012 04:16 AM|LINK
I think you can try this with the help of XDocument and start with the Value attribute, something like this:
var result = from item in XDocument.Load("xxx.xml").Descedants("name")
Nov 14, 2012 02:30 PM|LINK
Thanks for your responses
I'm new to Linq and I have tried unsucessfully to get both ideas to work.
Error messages included
Could not find file 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0
XDocument Descendants is not a member of string
VB code please
Thanks for your help
Nov 14, 2012 03:44 PM|LINK
For the first error (could not find file...), are you missing ~/ before the file name?
This might help for your second error:
Try implementing the code provided in the answer.