0

XElementを使用して、ユーザーがopenfiledialogから選択したXMLドキュメントを検索しています。

コードは次のとおりです。

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();
    }

queryString.textに基づくクエリをワイルドカードにしたい。

したがって、テキストフィールドには、混乱、吐き気、頭痛が含まれる可能性があります

queryStringテキストボックスにconfusionと入力しただけの場合でも、その要素とノードを配置する必要があります。

ありがとうございました

4

1 に答える 1

1

つまり、必要なのは次のように聞こえます。

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

それはあなたのために働きますか?

于 2013-03-26T17:04:38.197 に答える