搜索xml(文本框将数据输入到searchxml文件) [英] search xml (textbox entereddata to searchxml file)

查看:150
本文介绍了搜索xml(文本框将数据输入到searchxml文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,


我是使用xml的新手.所以我有一个要求,即我要在文本框中输入要搜索的内容,然后在xml中签入并在弹出窗口中显示匹配的数据.


我正在Windows应用程序中进行开发.

请让我知道如何搜索.


谢谢
Venkat.S

Hi Friends,


i am new for using xml .so i have one requirement ie i want search wt i m entered in textbox that i check in xml and display matching data in to popup window.


i am developing in windows app.

please give me any idea how to search.


Thanks
Venkat.S

推荐答案

请参阅我对问题的评论-尚不清楚.你知道吗?阅读XML解析的不同方法,学习如何做以及自己处理其余的内容,因为您无法清楚地解释它.

所以,这是您的选择:
Please see my comment to the question — it''s not clear. You know what? Read on the different ways of XML parsing, learn how to do it and deal with the rest on your own, as you cannot explain it clearly.

So, here are your options:

  1. 使用System.Xml.XmlDocument类.它实现了DOM接口;如果文档太大,则这种方法最简单,也足够好.
    请参见
  2. 使用类System.Xml.XmlTextReader; library/system.xml.xmldocument.aspx"target =" _ blank"title =" New Window> ^ ].
  3. 使用类System.Xml.XmlTextReader;这是最快的读取方法,尤其是您需要跳过一些数据.
    请参见 http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx [ http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [http://msdn.microsoft.com/en-us/library/bb387063.aspx [

  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^].
  2. Use the class System.Xml.XmlTextReader; this is the fastest way of reading, especially is you need to skip some data.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^].
  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].



玩得开心!


经过说明:在这种简单情况下,最有效的方法是System.Xml.XmlTextReader.它允许您只读.看下面的示例:
http://msdn.microsoft.com/zh-CN /library/system.xml.xmltextreader.read.aspx [ ^ ].这就是您需要做的:阅读全部内容;在旅途中,选择所需的节点类型.在您的示例中,该值必须为XmlNodeType.Text.将其作为文本并在其中搜索您的图案.在每次匹配的情况下,将结果添加到System.Collections.Generic.List<System.String>的实例中.最后,您将找到一个匹配列表.问题解决了.

—SA



Have fun!


After explanation: in this simple case, the most effective method would be System.Xml.XmlTextReader. It allows you to read forward-only. Look at this example: http://msdn.microsoft.com/en-us/library/system.xml.xmltextreader.read.aspx[^]. This is what you need to do: read it all to the end; on the road, pick up the types of nodes you need. In your example this must be XmlNodeType.Text. Take it text and search your pattern in it. Add results to the instance of System.Collections.Generic.List<System.String> in case of every match. At the end you will have a list of matches. Problem solved.

—SA


您可以为此使用LINQ
Hi You can use LINQ for this
XElement xe = XElement.Load("Your XML file path");
//Get all sub nodes in the xml data
var allsubnodes = xe.DescendantNodes().Where(e => e is XElement && !((XElement)e).HasElements).Select(a=> (XElement)a);

//Find and store all the matched data in an array.
var matched_values = allsubnodes.Where(nd => nd.Value.Contains("Text to Match")).Select(a=>a.Value).ToArray();



在这里,我正在使用包含进行搜索(以粗体突出显示),您可以自由使用任何字符串函数. :)

谢谢,
Debata



Here I am using contains for searching (Highlighted in bold), You are free to use any string function. :)

Thanks,
Debata


那没关系,朋友

但是我想输入第1列的值,然后在同一行中匹配column2的值并显示column2的值.
我输入第1列的值,并在行内获取第2列的值.

请理解我的说法.
thats ok friend

but i want to enter column 1 value and then i match column2 value in same row and display column2 value.
i enter column 1 value its go and get column2 value in within the row.

please understand my quation.


这篇关于搜索xml(文本框将数据输入到searchxml文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆