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. XML / XSL
  4. Reding xml node in windows Forms [modified]

Reding xml node in windows Forms [modified]

Scheduled Pinned Locked Moved XML / XSL
csharpvisual-studiowinformsxmllearning
3 Posts 3 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.
  • C Offline
    C Offline
    chakran
    wrote on last edited by
    #1

    Hi, am working on VS.net 2.0 windows application using c#. while am reading value of node in xml doc it is giving empty string.pls see the code below. can any one give me the solution where I had done mistake. XmlTextReader reader = new XmlTextReader(@"C:\book.xml"); while (reader.Read()) { reader.MoveToElement(); if (reader.Name == "year") { label1.Text = reader.Value.ToString(); } } book.xml file: <bookstore> <book category="COOKING"> <title lang="en"> Everyday Italian < /title> <author>Giada De Laurentiis </author> <year>2005 </year> <price>30.00 </price> </book> </bookstore> Thanks -- modified at 7:22 Thursday 6th September, 2007

    I C 2 Replies Last reply
    0
    • C chakran

      Hi, am working on VS.net 2.0 windows application using c#. while am reading value of node in xml doc it is giving empty string.pls see the code below. can any one give me the solution where I had done mistake. XmlTextReader reader = new XmlTextReader(@"C:\book.xml"); while (reader.Read()) { reader.MoveToElement(); if (reader.Name == "year") { label1.Text = reader.Value.ToString(); } } book.xml file: <bookstore> <book category="COOKING"> <title lang="en"> Everyday Italian < /title> <author>Giada De Laurentiis </author> <year>2005 </year> <price>30.00 </price> </book> </bookstore> Thanks -- modified at 7:22 Thursday 6th September, 2007

      C Offline
      C Offline
      Chetan Patel
      wrote on last edited by
      #2

      You can directly read the xml file in DataSet using ds.ReadXML("xmlfilename.xml"); now you can get each Tag as Columns

      Best Regards, Chetan Patel

      1 Reply Last reply
      0
      • C chakran

        Hi, am working on VS.net 2.0 windows application using c#. while am reading value of node in xml doc it is giving empty string.pls see the code below. can any one give me the solution where I had done mistake. XmlTextReader reader = new XmlTextReader(@"C:\book.xml"); while (reader.Read()) { reader.MoveToElement(); if (reader.Name == "year") { label1.Text = reader.Value.ToString(); } } book.xml file: <bookstore> <book category="COOKING"> <title lang="en"> Everyday Italian < /title> <author>Giada De Laurentiis </author> <year>2005 </year> <price>30.00 </price> </book> </bookstore> Thanks -- modified at 7:22 Thursday 6th September, 2007

        I Offline
        I Offline
        israr Ali NET
        wrote on last edited by
        #3

        XmlTextReader reader = null; try { //Load the reader with the XML file. reader = new XmlTextReader("c:\\book.xml"); //Parse the XML and display the text content of each of the elements. while (reader.Read()){ if (reader.IsStartElement()){ if (reader.IsEmptyElement) Console.WriteLine("<{0}/>", reader.Name); else{ Console.Write("<{0}> ", reader.Name); reader.Read(); //Read the start tag. if (reader.IsStartElement()) //Handle nested elements. Console.Write("\r\n<{0}>", reader.Name); Console.WriteLine(reader.ReadString()); //Read the text content of the element. } } } } finally { if (reader != null) reader.Close(); } try this code and remove space in your xml title closing tag in between < and / and put label1.text or what you like instead of Console.WriteLine . Everyday Italian !!< /title>!! <author>Giada De Laurentiis </author> <year>2005 </year> <price>30.00 </price> </book> </bookstore> Israr Ali</x-turndown>

        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