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.
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")
data.Load(path)
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
foundEmps.Add(empName)
End If
Next
Return foundEmps.ToArray()
DaveMon
Member
3 Points
19 Posts
First letter of the name begins with A.
Nov 13, 2012 02:20 PM|LINK
Hi everyone
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"?>
<Employers>
<name Employer="Abce"
</name>
<name Employer="abcde"
</name>
<name Employer="Bcdef"
</name>
<name Employer="Cdefg"
</name>
</Employers>
msmk
Participant
797 Points
180 Posts
Re: First letter of the name begins with A.
Nov 13, 2012 06:26 PM|LINK
Dim data As XmlDocument = New XmlDocument Dim path As String = HttpContext.Current.Server.MapPath("yourPath") data.Load(path) 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 foundEmps.Add(empName) End If Next Return foundEmps.ToArray()Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: First letter of the name begins with A.
Nov 14, 2012 04:16 AM|LINK
Hello,
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") where item.Attribute("Employer").Value.ToUpper().StartWith("A") select item;DaveMon
Member
3 Points
19 Posts
Re: First letter of the name begins with A.
Nov 14, 2012 02:30 PM|LINK
Hi
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
msmk
Participant
797 Points
180 Posts
Re: First letter of the name begins with A.
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:
http://stackoverflow.com/questions/604680/xdocument-descendants-not-returning-any-elements
Try implementing the code provided in the answer.
Good Luck