Parsing XML

This is a discussion on Parsing XML within the C# Programming forums, part of the General Programming Boards category; Code: using System; using System.Xml; namespace ParseXML { /// <summary> /// Summary description for Control. /// </summary> class Control { ...

  1. #1
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438

    Parsing XML

    Code:
    using System;
    using System.Xml;
    
    namespace ParseXML
    {
    	/// <summary>
    	/// Summary description for Control.
    	/// </summary>
    	class Control
    	{
    		/// <summary>
    		/// Loads RptSendMailConfig.xml and searches for the Logo tag.
    		/// </summary>
    		/// <param name="args"></param>
    		static void Main(string[] args)
    		{
    			//Declare a string for the SentraliantLogo
    			string logo = "logo";
    
                //Create a reader and load the XML file
    			XmlTextReader reader = new XmlTextReader("C:\\development\\C#\\ParseXML\\RptSendMailConfig.xml");
    
    			//Begin the read
    			while(reader.Read())
    			{
    				//Search for any element tag
    				if(reader.NodeType == XmlNodeType.Element)
    				{
    					//If you find a element tag, search to see if it is the logo element
    					if(reader.LocalName.Equals(logo))
    					{
    						Console.WriteLine("logo: {0}", reader.ReadString());
    						Console.ReadLine();
    					}
    				}
    			}
    		}
    	}
    }

  2. #2
    Unregistered
    Guest

    Cool

    What's it's purpose in a little detail ?

  3. #3
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    It loads an XML file, finds a certain element and returns the value of the element. Great for configuration files and such.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parsing Xml
    By deviousdexter in forum C# Programming
    Replies: 7
    Last Post: 04-24-2009, 06:29 AM
  2. Parsing XML with C without 3rd party libs
    By mike_morley in forum C Programming
    Replies: 13
    Last Post: 12-18-2008, 01:21 PM
  3. xml file parsing in C
    By lonbgeach in forum Tech Board
    Replies: 31
    Last Post: 12-14-2006, 01:14 AM
  4. XML Parsing
    By Mareq in forum C++ Programming
    Replies: 8
    Last Post: 11-09-2005, 08:20 PM
  5. Parsing XML in C++
    By CompiledMonkey in forum C++ Programming
    Replies: 9
    Last Post: 06-22-2004, 11:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21