So far I don’t got problems searching elements for example , the next block of code will load the xml file and then will search descendants (“recordinfomation”) which is a parent element in the XML file and returns child elements (“title”, “aut_FirstName, “aut_LastName, and “xmllink”) . My question is I would like to start my search at the root of the xml file and search all parent elements and not a specific one and return what I am returning in the following code. In another words search the whole document for specific child elements.
Dim XDoc As XElement = XElement.Load(MapPath("App_Data\Bookstore.xml"))
Dim elements = From row In XDoc.Descendants("recordinformtion") _
Where Regex.IsMatch(row.Element("title").Value, strfirstterm, RegexOptions.IgnoreCase) And Regex.IsMatch(row.Element("title").Value, strsecondterm, RegexOptions.IgnoreCase) And Regex.IsMatch(row.Element("title").Value, strthirdterm, RegexOptions.IgnoreCase) _
Select Name = row.Element("auth_FirstName").Value, last = row.Element("aut_LastName").Value, _
Capital = row.Element("title").Value, strURL = row.Attribute("xmllink").Value
Here is the whole code:
Dim XDoc As XElement = XElement.Load(MapPath("App_Data\Bookstore.xml"))
Dim strmessage As String
Dim strfirstterm, strsecondterm, strthirdterm As String
Dim lbl As New Label
strfirstterm = TextBox1.Text
strsecondterm = TextBox2.Text
strthirdterm = TextBox3.Text
Dim elements = From row In XDoc.Descendants("recordinformtion") _
Where Regex.IsMatch(row.Element("title").Value, strfirstterm, RegexOptions.IgnoreCase) And Regex.IsMatch(row.Element("title").Value, strsecondterm, RegexOptions.IgnoreCase) And Regex.IsMatch(row.Element("title").Value, strthirdterm, RegexOptions.IgnoreCase) _
Select Name = row.Element("auth_FirstName").Value, last = row.Element("aut_LastName").Value, _
Capital = row.Element("title").Value, strURL = row.Attribute("xmllink").Value
Dim v = elements.ToList()
strmessage = "Your search has returned no results. You might want to check spelling."
If v.Count <= 0 Then
lbl.Text = "<script language='javascript'>" & Environment.NewLine & _
"window.alert('" + strmessage + "') </script>"
Page.Controls.Add(lbl)
End If
'The datasource for the ListView1 is the strSudents
ListView1.DataSource = elements
'binding for the listView1 to our dataSource
ListView1.DataBind()