Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Comments
Sergey Alexandrovich Kryukov 16-Jun-11 5:17am    
What exactly to search? Element, attribute or the value of those? All of them? Where is the XML schema? Search criteria?..

So far, the question is not answerable.
--SA
vsiddi 16-Jun-11 5:42am    
i have xml file like
Collapse

<datapacket>
<rowdata>
<r_id>101
<r_name>R-12
<r_color>White

<rowdata>
<r_id>102
<r_name>R-22
<r_color>Green

<rowdata>
<r_id>103
<r_name>R-32
<r_color>White

<rowdata>
<r_id>104
<r_name>R-134A
<r_color>Light Blue



and i hve one textbox and button

now i enter some text in to textbox and i click button
then i search xml file like above data

for example entered textbox like 10 and clivk search button
i want to display matching with 10
like 100,101,102,103.........etc only for start 10.
Sergey Alexandrovich Kryukov 17-Jun-11 4:05am    
You did not answer the questions. Is is only element's text or attributes, or even tags?
--SA
Sergey Alexandrovich Kryukov 17-Jun-11 4:02am    
It does not look XML at all. Just look by yourself.
--SA

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. 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[^].


Have fun!

[EDIT]
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
 
Share this answer
 
v3
Comments
Wayne Gaylard 16-Jun-11 5:26am    
Some good links.
Sergey Alexandrovich Kryukov 16-Jun-11 11:17am    
Thank you, Wayne.
--SA
Hi You can use LINQ for this
MSIL
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();


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

Thanks,
Debata
 
Share this answer
 
v2
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900