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. how do i read the specific tag ?

how do i read the specific tag ?

Scheduled Pinned Locked Moved XML / XSL
questionxml
4 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.
  • Y Offline
    Y Offline
    YiXiang_89
    wrote on last edited by
    #1

    hi all This is to read the tag line by line. using System.Xml; ... ... ... XmlTextReader reader = new XmlTextReader ("reader.xml"); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an element. Console.Write("<" + reader.Name); Console.WriteLine(">"); break; case XmlNodeType.Text: //Display the text in each element. Console.WriteLine (reader.Value); break; case XmlNodeType.EndElement: //Display the end of the element. Console.Write("</" + reader.Name); Console.WriteLine(">"); break; } } Console.ReadLine(); How do i read the specific tag if i just want to read all the tag that have this < big > tag? thank you

    G P 2 Replies Last reply
    0
    • Y YiXiang_89

      hi all This is to read the tag line by line. using System.Xml; ... ... ... XmlTextReader reader = new XmlTextReader ("reader.xml"); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an element. Console.Write("<" + reader.Name); Console.WriteLine(">"); break; case XmlNodeType.Text: //Display the text in each element. Console.WriteLine (reader.Value); break; case XmlNodeType.EndElement: //Display the end of the element. Console.Write("</" + reader.Name); Console.WriteLine(">"); break; } } Console.ReadLine(); How do i read the specific tag if i just want to read all the tag that have this < big > tag? thank you

      G Offline
      G Offline
      George L Jackson
      wrote on last edited by
      #2

      This might help you get started:

      reader.ReadToFollowing("big");
      do
      {
      // Process data ...
      } while (reader.ReadToNextSibling("big"));

      "We make a living by what we get, we make a life by what we give." --Winston Churchill

      1 Reply Last reply
      0
      • Y YiXiang_89

        hi all This is to read the tag line by line. using System.Xml; ... ... ... XmlTextReader reader = new XmlTextReader ("reader.xml"); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an element. Console.Write("<" + reader.Name); Console.WriteLine(">"); break; case XmlNodeType.Text: //Display the text in each element. Console.WriteLine (reader.Value); break; case XmlNodeType.EndElement: //Display the end of the element. Console.Write("</" + reader.Name); Console.WriteLine(">"); break; } } Console.ReadLine(); How do i read the specific tag if i just want to read all the tag that have this < big > tag? thank you

        P Offline
        P Offline
        Perry Holman
        wrote on last edited by
        #3

        You can use XPath to simplify your work. For example: XmlDataDocument xmlDoc = new XmlDataDocument(); xmlDoc.Load("yourfile.xml"); XmlNodeList xmlNodeList = xmlDoc.SelectNodes("roottag/big"); //XPath expression More detail information pls. refer to Microsoft MSDN.

        Welcome to www.softwaretree.net! You can find many excellent audio/video converter tools there!

        G 1 Reply Last reply
        0
        • P Perry Holman

          You can use XPath to simplify your work. For example: XmlDataDocument xmlDoc = new XmlDataDocument(); xmlDoc.Load("yourfile.xml"); XmlNodeList xmlNodeList = xmlDoc.SelectNodes("roottag/big"); //XPath expression More detail information pls. refer to Microsoft MSDN.

          Welcome to www.softwaretree.net! You can find many excellent audio/video converter tools there!

          G Offline
          G Offline
          George L Jackson
          wrote on last edited by
          #4

          Unfortunately, our poster is using XmlTextReader. You don't use XPath with that.

          "We make a living by what we get, we make a life by what we give." --Winston Churchill

          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