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. Read XML Data from C#

Read XML Data from C#

Scheduled Pinned Locked Moved C#
csharpxmlquestionannouncement
2 Posts 2 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.
  • Q Offline
    Q Offline
    QuickDeveloper
    wrote on last edited by
    #1

    hi i need to read XML data from an XML file into C#.i tried using XmlTextReader class but i am not getting all elements. My XML file is as follows

    <?xml version="1.0"?>
    <Form1>
    <button>username</button>
    </Form1>

    My code is as follows

    // Create an instance of XmlTextReader and call Read method to read the file

            XmlTextReader textReader = new XmlTextReader("C:\\\\books.xml");
    
            textReader.Read();
    
            // If the node has value
    
            while (textReader.Read())
    
            {
    
                // Move to fist element
    
                textReader.MoveToElement();
    
    
                  Console.WriteLine("Attribute Count:" + textReader.Value.ToString());
            }
    

    in the above code i am not getting all the nodes and elements...(maybe due to whitespaces) please give links to any code samples etc...is there any other method to read?? thanks in advance...

    "Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"

    T 1 Reply Last reply
    0
    • Q QuickDeveloper

      hi i need to read XML data from an XML file into C#.i tried using XmlTextReader class but i am not getting all elements. My XML file is as follows

      <?xml version="1.0"?>
      <Form1>
      <button>username</button>
      </Form1>

      My code is as follows

      // Create an instance of XmlTextReader and call Read method to read the file

              XmlTextReader textReader = new XmlTextReader("C:\\\\books.xml");
      
              textReader.Read();
      
              // If the node has value
      
              while (textReader.Read())
      
              {
      
                  // Move to fist element
      
                  textReader.MoveToElement();
      
      
                    Console.WriteLine("Attribute Count:" + textReader.Value.ToString());
              }
      

      in the above code i am not getting all the nodes and elements...(maybe due to whitespaces) please give links to any code samples etc...is there any other method to read?? thanks in advance...

      "Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"

      T Offline
      T Offline
      tom572007
      wrote on last edited by
      #2

      Hi A nice example

      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