How to search a XML field which gives maxim search results
-
24. července 2012 9:09How to search a XML field which gives maxim search results . I use where statement it can only search the field and the correct match text.for example :if i have two feilds such as <title>baby</title><title>baby happy</title>and if i search the word baby it give me the first only as result.i want to get the second statement too since it also has the word baby.
Solve your Problems @ http://www.livetut.com/
Všechny reakce
-
24. července 2012 10:28Moderátor
How does the code you already have look like? (which technology are you using... ?)
Vitek Karas [MSFT]
-
24. července 2012 11:02
How does the code you already have look like? (which technology are you using... ?)
Vitek Karas [MSFT]
the where statement only solves the problem of getting the exact value of one field from the XML file. Want to display all matching text like both.If i search baby it must give both values not only the exact value
<title>baby</title><title>baby happy</title>if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) { MessageBox.Show("No network connection available!"); return; } // start loading XML-data WebClient downloader = new WebClient(); Uri uri = new Uri("http://app.livehub.org/xml/funnyvideo.xml", UriKind.Absolute); downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(EmployeesDownloaded); downloader.DownloadStringAsync(uri); } void EmployeesDownloaded(object sender, DownloadStringCompletedEventArgs e) { if (e.Result == null || e.Error != null) { MessageBox.Show("There was an error downloading the XML-file!"); } else { // Deserialize if download succeeds XmlSerializer serializer = new XmlSerializer(typeof(Employees)); XDocument document = XDocument.Parse(e.Result); // Employees employees = (Employees)serializer.Deserialize(document.CreateReader()); // employeesList.ItemsSource = employees.Collection; Employees employees = (Employees)serializer.Deserialize(new StringReader(e.Result)); employeesList.ItemsSource = employees.Collection.Where(emp => emp.title == textBox1.Text).ToList();
Solve your Problems @ http://www.livetut.com/
-
24. července 2012 11:22
Hi,
Have you tried something like this?
employeesList.ItemsSource = employees.Collection.Where(emp => emp.title.Contains(textBox1.Text)).ToList();
- Označen jako odpověď vensilver 24. července 2012 12:28
-
24. července 2012 12:10
it is still case sensitive.if the xml field is "Baby" and the user type it as "baby" the application dos not display resultHi,
Have you tried something like this?
employeesList.ItemsSource = employees.Collection.Where(emp => emp.title.Contains(textBox1.Text)).ToList();
Solve your Problems @ http://www.livetut.com/
-
24. července 2012 12:17
This case you should use Use ToLower() for example:
employeesList.ItemsSource = employees.Collection.Where(emp => emp.title.ToLower().Contains(textBox1.Text.ToLower())).ToList();
- Označen jako odpověď vensilver 24. července 2012 12:28
-
25. července 2012 10:38
Sir,
i started to face a new problem i add the code in to a button click event.When i perform search it works fine.Then when i click on any list item it move to the next page.But when i use the back button and come back and perform a new search the application exits saying the at it says
System.NullReferenceException was unhandled
Message=NullReferenceException
StackTrace:
at Employees.EmployeePage.MainPage_Loaded(Object sender, RoutedEventArgs e)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
here is my main page
namespace Employees { public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { InitializeComponent(); } // selection in EmployeeList is changed private void employeesList_SelectionChanged(object sender, SelectionChangedEventArgs e) { var app = App.Current as App; app.selectedEmployee = (Employee)employeesList.SelectedItem; this.NavigationService.Navigate(new Uri("/EmployeePage.xaml", UriKind.Relative)); } private void search_Click(object sender, RoutedEventArgs e) { // is there network connection available if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) { MessageBox.Show("No network connection available!"); return; } // start loading XML-data WebClient downloader = new WebClient(); Uri uri = new Uri("http://app.livehub.org/xml/funnyvideo.xml", UriKind.Absolute); downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(EmployeesDownloaded); downloader.DownloadStringAsync(uri); } void EmployeesDownloaded(object sender, DownloadStringCompletedEventArgs e) { if (e.Result == null || e.Error != null) { MessageBox.Show("There was an error downloading the XML-file!"); } else { // Deserialize if download succeeds XmlSerializer serializer = new XmlSerializer(typeof(Employees)); XDocument document = XDocument.Parse(e.Result); // Employees employees = (Employees)serializer.Deserialize(document.CreateReader()); // employeesList.ItemsSource = employees.Collection; Employees employees = (Employees)serializer.Deserialize(new StringReader(e.Result)); employeesList.ItemsSource = employees.Collection.Where(emp => emp.title.ToLower().Contains(textBox1.Text.ToLower())).ToList(); } } } }
Solve your Problems @ http://www.livetut.com/
- Upravený vensilver 25. července 2012 12:15
-
27. července 2012 7:19Ur new problem isn't a xml issue, You can post in this forum: http://social.msdn.microsoft.com/Forums/en/category/visualcsharp
-
27. července 2012 7:51i have solved the problem it was just a exception
Solve your Problems @ http://www.livetut.com/