I am trying to display xml keys and corresponding values..
I have the following code that works, but i am supposed to use XPath, XMLDocument and XmlNode.
Can someone help ? Not familiar with those:
using
System;
using
System.IO;
public
class ReadXMLFile
{
public static void Main(string[] args)
{
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader(args[0]))
{
String line;
String mkey;
String mvalue;
// reads and displays values of the file until the end of the file is reached
while ((line = sr.ReadLine()) != null)
{
mkey="";
mvalue="";
if ((line.IndexOf("key=") > 0) && (line.IndexOf("value=") > 0))
{
mkey = line.Substring(line.IndexOf("key=")+5);
mkey = mkey.Substring(0,mkey.IndexOf("\""));
mvalue = line.Substring(line.IndexOf("value=")+7);
mvalue = mvalue.Substring(0,mvalue.IndexOf("\""));
Console.WriteLine("Key={0} || Value={1}",mkey,mvalue);
}
}
Console.ReadLine();
}
}
catch (Exception e)
{
// Incase something is wrong, we should let the user know.
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
}
}