In a visual C# project i want to pass a XML Document Object to a method. In that method i should Read the values which i stored inside the XML Document object. Without creating an XML File.
Thanks for the Reply guys i finally got my piece of code.
//use following code when assign values to XMlDocument
XMLOBJECT()
{
XmlDocument xmlEmployee = new XmlDocument();
XmlElement xmlRoot = xmlEmployee.CreateElement("HR");
XmlElement xmlEmployees = xmlEmployee.CreateElement("Employee");
xmlEmployees.SetAttribute("Name", "XYZ");
xmlEmployees.SetAttribute("DOB", "12/12/2010");
xmlRoot.AppendChild(xmlEmployees);
xmlEmployee.AppendChild(xmlRoot);
Employee Emp=new EMployee();
Emp.retriveXMl(xmlEmployee);
}
In the above code our XML object is created now we can pass the Xml object.
//Use Following code when assign values to Employee Object
class employee
{
retrivelXMl(XMLDOCUMENT xmlEmployeeobject)
{
string NAME;
int DOB;
XmlNodeList xmlEmployees = xmlEmployeeobject.SelectNodes("//Employee");
foreach (XmlElement Employee in xmlEmployees)
{
NAME = Employee.GetAttribute("Name"));
DOB = int.parse(Employee.GetAttribute("DOB"));
}
}
}