XML file reading
-
Can anyone tell me how to read all the nodes and their InnerText of an xml file?
-
Can anyone tell me how to read all the nodes and their InnerText of an xml file?
-
Can anyone tell me how to read all the nodes and their InnerText of an xml file?
sample to read all the nodes of XML file string[] sb=new string[4]{"","","",""}; XmlDocument doc = CreateDoc(XmlFile); XmlNode root = doc.SelectSingleNode("FormatModule/Leads/Contents"); XmlNode root1; string fieldname; foreach(XmlNode node in root.ChildNodes) { if(root.NodeType != XmlNodeType.Comment) { string str=node.Name; switch(str) { case "Body1": root1=doc.SelectSingleNode("FormatModule/Leads/Contents/Body1"); foreach(XmlNode n in root1.ChildNodes) { if(n.NodeType != XmlNodeType.Comment) { XmlAttribute name = n.Attributes["type"]; if(name.InnerText=="text") { sb[0]+=n.InnerText.ToString()+"\n\n"+" "; } if(name.InnerText=="Field") { fieldname=n.Attributes["FieldName"].InnerText.Trim(); sb[0]+=DataLeads(id,fieldname); } } } break; return sb; } Hope u might be knowing how to creaate XML file Rizwan Afsar Associate Member, Technical Team IAP Company Ltd, Gurgaon INDIA www.iap-online.com
-
Can anyone tell me how to read all the nodes and their InnerText of an xml file?
Hi, You can also have a look at the code below..Hope it's useful to u.. class ReadXml { //private const String filename = "c:\\ala.xml"; private const String filename ="data.xml"; static void Main(string[] args) { XmlTextReader txtreader = null; XmlValidatingReader reader = null; try { // Load the reader with the data file and ignore // all whitespace nodes. txtreader = new XmlTextReader(filename); txtreader.WhitespaceHandling = WhitespaceHandling.None; // Implement the validating reader over the text reader. reader = new XmlValidatingReader(txtreader); reader.ValidationType = ValidationType.None; // Parse the file and display each of the nodes. while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: Console.Write("\t<{0}>\n", reader.Name); break; case XmlNodeType.Text: Console.Write("\t{0}\n",reader.Value); break; case XmlNodeType.CDATA: Console.Write("", reader.Value); break; case XmlNodeType.ProcessingInstruction: Console.Write("", reader.Name, reader.Value); break; case XmlNodeType.Comment: Console.Write("", reader.Value); break; case XmlNodeType.XmlDeclaration: Console.Write("\n"); break; case XmlNodeType.Document: break; case XmlNodeType.DocumentType: Console.Write("\n", reader.Name); break; } } } finally { if (reader!=null) reader.Close(); } Console.ReadLine(); } } Thank you, Vaibhav