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. Help

Help

Scheduled Pinned Locked Moved XML / XSL
csharplinqgraphicsxmlhelp
6 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.
  • M Offline
    M Offline
    MrMcIntyre
    wrote on last edited by
    #1

    Hi I have created a C# XML Reader and was wondering if someone could have a look at the code to see if I have done it right. Thanks Andrew ------------------------------- using System; using System.Xml; using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace MyProject { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { System.IO.StreamReader stream = new System.IO.StreamReader ("About.xml"); XmlTextReader reader = null; reader = new XmlTextReader (stream); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an Element. Console.Write("<" + reader.Name); while (reader.MoveToNextAttribute()) // Read attributes. Console.Write(" " + reader.Name + "='" + reader.Value + "'"); Console.Write(">"); Console.WriteLine(">"); break; case XmlNodeType.Text: //Display the text in each element. Console.WriteLine (reader.Value); break; case XmlNodeType. EndElement: //Display end of element. Console.Write("</" + reader.Name); Console.WriteLine(">"); break; } } } } }

    Andrew McIntyre

    M M L 4 Replies Last reply
    0
    • M MrMcIntyre

      Hi I have created a C# XML Reader and was wondering if someone could have a look at the code to see if I have done it right. Thanks Andrew ------------------------------- using System; using System.Xml; using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace MyProject { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { System.IO.StreamReader stream = new System.IO.StreamReader ("About.xml"); XmlTextReader reader = null; reader = new XmlTextReader (stream); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an Element. Console.Write("<" + reader.Name); while (reader.MoveToNextAttribute()) // Read attributes. Console.Write(" " + reader.Name + "='" + reader.Value + "'"); Console.Write(">"); Console.WriteLine(">"); break; case XmlNodeType.Text: //Display the text in each element. Console.WriteLine (reader.Value); break; case XmlNodeType. EndElement: //Display end of element. Console.Write("</" + reader.Name); Console.WriteLine(">"); break; } } } } }

      Andrew McIntyre

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      Hi Andrew. This isn't the best way to ask a question on CodeProject. What you'll want to do instead is try out your code and if it isn't working the way you expect or want, ask a specific question that targets what is going wrong (for example, it's better for volunteers to read through four lines of code that target where you think the problem is, rather than go through a full dump of code... and if you make it easier for volunteers to help you, they will!) [EDIT] - oh, and it's never a good idea to use "Help" for the subject line. Everyone already knows you're looking for help, otherwise you wouldn't be posting here. A subject line that helps focus on the specific question you have in mind is much better and easier for volunteers to work with.

      MishaInTheCloud.blogspot.com

      1 Reply Last reply
      0
      • M MrMcIntyre

        Hi I have created a C# XML Reader and was wondering if someone could have a look at the code to see if I have done it right. Thanks Andrew ------------------------------- using System; using System.Xml; using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace MyProject { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { System.IO.StreamReader stream = new System.IO.StreamReader ("About.xml"); XmlTextReader reader = null; reader = new XmlTextReader (stream); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an Element. Console.Write("<" + reader.Name); while (reader.MoveToNextAttribute()) // Read attributes. Console.Write(" " + reader.Name + "='" + reader.Value + "'"); Console.Write(">"); Console.WriteLine(">"); break; case XmlNodeType.Text: //Display the text in each element. Console.WriteLine (reader.Value); break; case XmlNodeType. EndElement: //Display end of element. Console.Write("</" + reader.Name); Console.WriteLine(">"); break; } } } } }

        Andrew McIntyre

        M Offline
        M Offline
        MrMcIntyre
        wrote on last edited by
        #3

        Everytime I debug the project and when the client appear the XML document that I want to appear doesn't appear on screen for some reason. I get no error in the error list and thats why I have asked you guy's. Andrew

        Andrew McIntyre

        M 1 Reply Last reply
        0
        • M MrMcIntyre

          Everytime I debug the project and when the client appear the XML document that I want to appear doesn't appear on screen for some reason. I get no error in the error list and thats why I have asked you guy's. Andrew

          Andrew McIntyre

          M Offline
          M Offline
          Mike Ellison
          wrote on last edited by
          #4

          Well, running under the assumption that your about.xml file isn't empty, you may want to handle the other node types in your switch statement as you could be skipping the content. The MSDN documentation has a good sample that is pretty close to what you coded, and includes the other node types. http://msdn.microsoft.com/en-us/library/system.xml.xmltextreader.read.aspx[^]

          MishaInTheCloud.blogspot.com

          1 Reply Last reply
          0
          • M MrMcIntyre

            Hi I have created a C# XML Reader and was wondering if someone could have a look at the code to see if I have done it right. Thanks Andrew ------------------------------- using System; using System.Xml; using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace MyProject { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { System.IO.StreamReader stream = new System.IO.StreamReader ("About.xml"); XmlTextReader reader = null; reader = new XmlTextReader (stream); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an Element. Console.Write("<" + reader.Name); while (reader.MoveToNextAttribute()) // Read attributes. Console.Write(" " + reader.Name + "='" + reader.Value + "'"); Console.Write(">"); Console.WriteLine(">"); break; case XmlNodeType.Text: //Display the text in each element. Console.WriteLine (reader.Value); break; case XmlNodeType. EndElement: //Display end of element. Console.Write("</" + reader.Name); Console.WriteLine(">"); break; } } } } }

            Andrew McIntyre

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Try using the debugger. Put a breakpoint on the first "Console.WriteLine" statement, then examine program variables and single step through the code to try and discover where you are going wrong.

            1 Reply Last reply
            0
            • M MrMcIntyre

              Hi I have created a C# XML Reader and was wondering if someone could have a look at the code to see if I have done it right. Thanks Andrew ------------------------------- using System; using System.Xml; using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace MyProject { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { System.IO.StreamReader stream = new System.IO.StreamReader ("About.xml"); XmlTextReader reader = null; reader = new XmlTextReader (stream); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an Element. Console.Write("<" + reader.Name); while (reader.MoveToNextAttribute()) // Read attributes. Console.Write(" " + reader.Name + "='" + reader.Value + "'"); Console.Write(">"); Console.WriteLine(">"); break; case XmlNodeType.Text: //Display the text in each element. Console.WriteLine (reader.Value); break; case XmlNodeType. EndElement: //Display end of element. Console.Write("</" + reader.Name); Console.WriteLine(">"); break; } } } } }

              Andrew McIntyre

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Well I downloaded your code and it works fine. EXCEPT, this is a WinForms application and you are displaying the information via Console.WriteLine so all the output is going to the console output window rather than being displayed in your windows form. I would suggest that you spend some more time learning how to use WinForms applications before proceeding further.

              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