To read XML, you use XmlTextReader . You can read XML from a file, a stream, or a URL, as demonstrated in the following examples.
using System;
using System.IO;
using System.Xml;
namespace Client.Chapter_22___XML
{
class Test
{
private const string doc = "Test.xml";
static void Main(string[] args)
{
XmlTextReader reader = null;
//Load the file with an XmlTextReader
reader = new XmlTextReader(doc);
//Read the file
while (reader.Read())
{
//TODO -
}
if (reader != null)
reader.Close();
}
}
}
using System; using System.IO; using System.Xml; namespace Client.Chapter_22___XML { class Test { static void Main(string[] args) { StringReader stream; XmlTextReader reader = null; stream = new StringReader(" XML File Text"); //Load the XmlTextReader from the stream reader = new XmlTextReader(stream); while (reader.Read()) { //TODO - } if (reader != null) reader.Close(); } } }
using System; using System.IO; using System.Xml; namespace Client.Chapter_22___XML { class Test { static void Main(string[] args) { string localURL = "http:\\Test\\Test.xml"; XmlTextReader myXmlURLreader = null; myXmlURLreader = new XmlTextReader (localURL); while (myXmlURLreader.Read()) { //TODO - } if (myXmlURLreader != null) myXmlURLreader.Close(); } } }