hi, how can i read xmlnode in c#.net [modified]
-
hi, i want to read one particular Xml_node in c#.net how can i read that node plz give sample code for that . in the below xml file i want read node only and that phone_no child nodes text is stored in listbox. /* < < <a <b <c < < <9898776 <8272679 <7t8124748 < < <gsdghgkef <guiqweu3r <io34uiiju < < */ Thanks -- modified at 2:07 Wednesday 13th September, 2006
-
hi, i want to read one particular Xml_node in c#.net how can i read that node plz give sample code for that . in the below xml file i want read node only and that phone_no child nodes text is stored in listbox. /* < < <a <b <c < < <9898776 <8272679 <7t8124748 < < <gsdghgkef <guiqweu3r <io34uiiju < < */ Thanks -- modified at 2:07 Wednesday 13th September, 2006
Hi, To read the XML file or string you can use the XmlDocument class which is in the System.XML namespace.
XmlDocument doc = new XmlDocument();
doc.Load("xmlstring");
doc.LoadXML("xmlfile");
XmlNode root = doc.DocumentElement;
XmlNodeList list = root.ChildNodes;
foreach(XmlNode node in list)
{
if(node.HasChildNodes)
{
XmlNodeList list1 = node.ChildNodes;
foreach(....)
{}
}
else
{
string name=node.Name;
string text=node.InnerText;
}
}Hope this code helps you.
Do your best to be the best
-
hi, i want to read one particular Xml_node in c#.net how can i read that node plz give sample code for that . in the below xml file i want read node only and that phone_no child nodes text is stored in listbox. /* < < <a <b <c < < <9898776 <8272679 <7t8124748 < < <gsdghgkef <guiqweu3r <io34uiiju < < */ Thanks -- modified at 2:07 Wednesday 13th September, 2006
You would use XmlDocument, but you'd use XPath to go direct to your node, as in foreach(XmlNode node in doc.SelectNodes("//deatails/phone_no/No")) And to do this, you'd fix your schema and replace No1, No2 and No3 with nodes that all have the same name ( and a number as an attribute if you need it for number, but the order will never change anyhow ).
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
You would use XmlDocument, but you'd use XPath to go direct to your node, as in foreach(XmlNode node in doc.SelectNodes("//deatails/phone_no/No")) And to do this, you'd fix your schema and replace No1, No2 and No3 with nodes that all have the same name ( and a number as an attribute if you need it for number, but the order will never change anyhow ).
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
hi , thanks for giving helpful idea. i try that but in, i can't get the data of node plz check my code give any modifications. iam new to c#.net and xml private void button1_Click(object sender, System.EventArgs e) { string filename = "C:\\C#program\\cs_programs\\singlenode\\bin\\Debug\\nodexml.xml"; XmlTextReader tr = new XmlTextReader(filename); XmlDocument doc = new XmlDocument(); while(tr.Read()) { foreach(XmlNode node in doc.SelectNodes("//details/add/addr")) listBox1.Items.Add(doc.Value); } }
-
hi , thanks for giving helpful idea. i try that but in, i can't get the data of node plz check my code give any modifications. iam new to c#.net and xml private void button1_Click(object sender, System.EventArgs e) { string filename = "C:\\C#program\\cs_programs\\singlenode\\bin\\Debug\\nodexml.xml"; XmlTextReader tr = new XmlTextReader(filename); XmlDocument doc = new XmlDocument(); while(tr.Read()) { foreach(XmlNode node in doc.SelectNodes("//details/add/addr")) listBox1.Items.Add(doc.Value); } }
Like I said, your schema is useless. You need to change the addr1/addr2/addr3 nodes to all be just addr. And don't forget, XML is case sensitive.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Like I said, your schema is useless. You need to change the addr1/addr2/addr3 nodes to all be just addr. And don't forget, XML is case sensitive.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
hi Christian i new to c#.net i want to access one node in xmlfile using c#.net . that node have child node (i want that child node values) i write my xml file like this < < <Ap <MP <UP < <gjsefgjkl<dfhtyxcvd<ioiopweri < in this i want to access the "add" child node value. i wrote c#.net code like this, "When i press Button the childnode("add") values r stored in listbox " plz change any modification in my code or plz give code how to access thatnode private void button1_Click(object sender, System.EventArgs e) { string filename = "C:\\C#program\\cs_programs\\singlenode\\bin\\Debug\\nodexml.xml"; XmlTextReader tr = new XmlTextReader(filename); XmlDocument doc = new XmlDocument(); while(tr.Read()) { foreach(XmlNode node in doc.SelectNodes("//details/add/addr")) listBox1.Items.Add(tr.Value); } } Thanks
-
hi Christian i new to c#.net i want to access one node in xmlfile using c#.net . that node have child node (i want that child node values) i write my xml file like this < < <Ap <MP <UP < <gjsefgjkl<dfhtyxcvd<ioiopweri < in this i want to access the "add" child node value. i wrote c#.net code like this, "When i press Button the childnode("add") values r stored in listbox " plz change any modification in my code or plz give code how to access thatnode private void button1_Click(object sender, System.EventArgs e) { string filename = "C:\\C#program\\cs_programs\\singlenode\\bin\\Debug\\nodexml.xml"; XmlTextReader tr = new XmlTextReader(filename); XmlDocument doc = new XmlDocument(); while(tr.Read()) { foreach(XmlNode node in doc.SelectNodes("//details/add/addr")) listBox1.Items.Add(tr.Value); } } Thanks
Well, if you want to access the add node, just drop the rest of the XPath - /details/add If you want to get all the addr nodes, name them all addr, as I advised you to do in the first place.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog