I want to get the contact node where corresponding name is provided.
please help me I am just starting xml.
Thank you in advance.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
DamodarPosted Aug 6, 2010, 3:14 PM
Please mark as answer if you are satisfied.
Tanmay SarkarPosted Aug 7, 2010, 10:41 AM
Thank you sir :)
Sam HobbsPosted Aug 7, 2010, 10:05 AM
Tanmay SarkarPosted Aug 7, 2010, 6:36 AM
Please put here sir your article link. specially want to learn XmlSerializer .
Thank you sir. I am waiting.....
Sam HobbsPosted Aug 7, 2010, 3:25 AM
Also, if you are not familiar with the XmlSerializer Class then look at my article in this web site about the XmlSerializer Class; it does not use SQL but it is worth knowing about.
Tanmay SarkarPosted Aug 7, 2010, 1:52 AM
you take my point what i am want perfectly ....
Thank you sir :)
Sam HobbsPosted Aug 7, 2010, 1:23 AM
There are many ways to do many things and many times the first suggestion is not always the best for you.
Tanmay SarkarPosted Aug 7, 2010, 12:35 AM
so the code will be like,
if (pdata.Name == "contact")
{
MessageBox.Show("contact no : " + pdata.InnerText);
rtnval = "N";
}
it's work fine now.
Thank you so much! :)
Tanmay SarkarPosted Aug 7, 2010, 12:21 AM
like:- ..... where name 'tanmay'
there will be two text field one will provide name by user & click button & another field will show the contact. That's my basic thing. And when I starting sql it was also my basic program on that time.
Thank you! :)
Sam HobbsPosted Aug 6, 2010, 5:42 PM
Tanmay SarkarPosted Aug 6, 2010, 1:35 PM
private void button1_Click(object sender, EventArgs e)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load("test.xml");
XmlNode node = xmldoc.DocumentElement;
foreach (XmlNode phonelist in node.ChildNodes)
{
foreach (XmlNode pbdat in phonelist.ChildNodes)
{
if (pbdat.InnerText == "Tanmay")
{
if (pbdat.Name == "contact")
{
string contactno = pbdat.InnerText;
MessageBox.Show(contactno);
}
}
}
}
}
If you have a little bit time can you please upload your cs file.
Thank you in advance.
DamodarPosted Aug 6, 2010, 1:17 PM
foreach( XmlNode phonelist in node.ChildNodes)
{
foreach (XmlNode pbdat in phonelist.ChildNodes)
{
if (pbdat.InnerText == "tanmay")
{
if(pbdat.Name == "contact")
{
string contactno = InfoNode.Innertext;
// this gives you the contact no when the name is given.
}
}
}
you told u only had one Information parent node. so i wrote only one foreach loop. Try this it should work now.
Tanmay SarkarPosted Aug 6, 2010, 1:08 PM
So i change it to string contactno = InfoNode.InnerText.ToString();
but it not showing any thing! Is i have a mistake?
My xml file is as follows.
help please..
DamodarPosted Aug 6, 2010, 12:38 PM
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load ("File");
XmlNode node = xmldoc.DocumentElement;
foreach (XmlNode InfoNode in node.ChildNodes)
{
if (InfoNode.InnerText == "tanmay")
{
if(InfoNode.Name == "contact")
{
string contactno = InfoNode.Innertext;
// this gives you the contact no when the name is given.
}
}
}
use this .. may be this will help you.