Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. XML file reading

XML file reading

Scheduled Pinned Locked Moved C#
xmltutorialquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rahultaing
    wrote on last edited by
    #1

    Can anyone tell me how to read all the nodes and their InnerText of an xml file?

    G R V 3 Replies Last reply
    0
    • R rahultaing

      Can anyone tell me how to read all the nodes and their InnerText of an xml file?

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Use an XmlDocument object to open the file. The DocumentElement propery is a reference to the root element that contains the nodes. --- b { font-weight: normal; }

      1 Reply Last reply
      0
      • R rahultaing

        Can anyone tell me how to read all the nodes and their InnerText of an xml file?

        R Offline
        R Offline
        rizwan afsar
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • R rahultaing

          Can anyone tell me how to read all the nodes and their InnerText of an xml file?

          V Offline
          V Offline
          VaibhavJ
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups