1

i want to fetch elements through search pattern like if i type "an" then i want all elements which have "an" example =man, animal, fan, pant

this is my code here i use foreach loop to display all search elements but i don't want to use foreach loop just i want to fetch all the list directly form xpath query please help me out its very impotent for me

private void Search2_Click_1(object sender, EventArgs e)
        {


            XmlNodeList nodes = myxml.DocumentElement.SelectNodes("/students/student/s_name" );

            string ha = search.Text;

            if (listbox11.Text == "Name")
            foreach(XmlNode node in nodes)
            {

                if(System.Text.RegularExpressions.Regex.IsMatch(node.InnerText,ha))
                { 
                    listBox1.Text += node.InnerText + "\r\n"; 
                }

            }

        }

2 Answers 2

1

Use this

private void Search2_Click_1(object sender, EventArgs e)
        {
  string ha = search.Text;

XmlNodeList nodes = myxml.DocumentElement.SelectNodes("/students/student/[contains(s_name,ha)]");

}
Sign up to request clarification or add additional context in comments.

2 Comments

how to write same regular expression in VB6 ....is anything i need to add reference to run regular expression
Dim ha As String ha = searchText.Text Set nodes = doc.documentElement.selectNodes("//s_name[descendant-or-self::*[contains(.,'" & ha + "')]]")
0

**The code which i write is simple, xpath query will fetch only related elements nodes but if you want to print then use foreach loop **

private void Search2_Click_1(object sender, EventArgs e) {

       string ha = search.Text;

        if (listbox11.Text == "Name")
        {
            listBox1.Text = "";

            XmlNodeList nodes = myxml.DocumentElement.SelectNodes("//s_name[descendant-or-self::*[contains(.,'" + ha + "')]]");
            foreach (XmlNode node in nodes)
            {


                    listBox1.Text += node.InnerText + "\r\n";


            }
        }

    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.