Tuesday, June 23, 2009

Reading a XML file..

hi all,

Here is the code for reading all node or selected node of a XML file. We just have to take a xmlTextReader object and using that we can read the content of the xml file.



XmlTextReader xRead = new XmlTextReader((Application.StartupPath + "\\" + strNewFile));
try
{
//Reading the XML file
while (xRead.Read())
{
XmlNodeType nodeType = xRead.NodeType;

if (nodeType == XmlNodeType.Element)
{
if ((xRead.Name == "graphic") || (xRead.Name == "inline-graphic"))
{
if (xRead.HasAttributes)
{
xRead.MoveToAttribute(0);
strImagename = xRead.Value;
}
}
}
}
}

Thanks
Anil Kumar Pandey
System Architect
Green Point Technology (India) Ltd.
Mumbai, Maharshtra
INDIA

Kontera