0

I am using XElement to search a XML document that a user selects through openfiledialog.

Here is the code:

private void dothis()
    {
        string query;

        XElement xml = XElement.Load(path);
        XNamespace ns = xml.GetDefaultNamespace();
        IEnumerable<XElement> symptoms = 


        from item in xml.Descendants(ns + "section")

        where (string) item.Element(ns + "text") == queryString.Text
        select item;

        // Execute the query 
        foreach (var complaints in symptoms)
        {
            // Instantiate the writer
            _writer = new TextBoxStreamWriter(txtConsole);
            // Redirect the out Console stream
            Console.SetOut(_writer);


            Console.WriteLine(complaints);

        }

        //Pause the application 
        Console.ReadLine();
    }

I want to make the query that is based on queryString.text be a wildcard.

So the text field might contain Confusion, Nausea, Headache

If I just type confusion into my queryString text box, then I want it still to located that element and node.

Thank you

leppie
  • 115,091
  • 17
  • 196
  • 297

1 Answers1

1

So it sounds like all you want is:

where item.Element(ns + text).Value.Contains(queryString.Text)

Would that work for you?

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194