This is the XML that i want to read.
<Server ServerName="SP-SWD-T01">
Some nodes are there
</Server>
I want to read the ServerName inside the server how can i read it.Please help.
This is the code
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.IgnoreComments = false;
XmlReader xmlRdr = XmlReader.Create(strFilePath, readerSettings);
// Parse the file
while (xmlRdr.Read())
{
switch (xmlRdr.NodeType)
{
case XmlNodeType.Element:
// You may need to capture the last element to provide a context
// for any comments you come across... so copy xmlRdr.Name, etc.
break;
case XmlNodeType.Comment:
MessageBox.Show(xmlRdr.Name);
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;
}
}
Thanks
try this