Click here to Skip to main content
15,896,526 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to make search which searches records from xml file.Below is my xml file.




dtable
id 2 id
name jigar name
phone_no 12345 phone_no
/dtable

dtable
id 3 id
name ajay name
phone_no 7777 phone_no
/dtable

dtable
id 4 id
name bhargav name
phone_no 4444 phone_no
/dtable



i want to do is,When user searches for id="2",it should display name and phone no.My question is how to search from xml file?any help is appreciated.
Posted
Updated 22-Oct-12 21:13pm
v2

Try following code

XML
XmlDcoument xDoc = new XmlDocument();
xDoc.Load("YourXml.XML");
 
XmlNode xNode = xDoc.DocumentElement.SelectSingleNode("dtable[id=2]");


This will give you the dtable node which has id=2

Now, to read the other node use following


XML
foreach (XmlNode child in xNode)
{
   Response.Write(child.LocalName);
   Response.Write(":");
   Response.Write(child.InnerText);
   Response.Write("\n");
}


Hope that helps. If it does, mark the answer as solution and/or upvote.

Thanks
Milind
 
Share this answer
 
Comments
Thanks7872 23-Oct-12 6:16am    
m getting error for "Response" that : "An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Response.get" can you make it out?
MT_ 23-Oct-12 6:18am    
Rohan, Response.write, I am just using to show the value. You can use child.LocalName and Child.InnerText to use the child node value the way you want. Hope that helps
Thanks7872 23-Oct-12 6:49am    
I solved it.the problem was i was using it inside static member which is not allowed.thanks for your kind support
MT_ 23-Oct-12 7:44am    
Welcome. Glad it helped.

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