C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Read XML file in C# class library


Posted Date: 01 Aug 2008      Total Responses: 2

Posted By: vijayendra krishna salunkhe       Member Level: Bronze     Points: 1


I have a xml file in c# class library, My class library has static class in this static class i want to read this xml file, but i failed to do it. As server object is not available in class library i couldn't able to use server object & Mappath function. Because file is physically present on class library folder there must be some option to read it.
can anybody guide me on this issue?




Responses

Author: Arjunvino    02 Aug 2008Member Level: SilverRating:     Points: 6
hi this is the Example for Reading XML File:

you can call this function where you want...


void LoadXML()
{

XmlDocument xmlStaffRegistry = new XmlDocument();
int nodeCount = 0;
string filePath = HttpContext.Current.Request.PhysicalApplicationPath.ToString() + "CourtsXML.xml";
xmlStaffRegistry.Load(filePath);

XmlNodeList xmlNodeList = null;

xmlNodeList = xmlStaffRegistry.ChildNodes;
nodeCount = xmlNodeList.Count;
for (int i = 0; i < nodeCount; i++)
{
if (xmlNodeList.Item(i).Name == "root")
{
XmlNodeList nodeListEnglish = null;
XmlNodeList nodeListDivehi = null;
nodeListEnglish = xmlStaffRegistry.SelectNodes("root/Language/English/caseconcludeddebtwiththecasetypewise");
nodeListDivehi = xmlStaffRegistry.SelectNodes("root/Language/Divehi/caseconcludeddebtwiththecasetypewise");

if (language == "Eng")
{
foreach (XmlNode english in nodeListEnglish)
{
lblMagistrate.Text = english.SelectSingleNode("jdmg").InnerText;
lblCaseType.Text = english.SelectSingleNode("cstype").InnerText;
lblApplicantOrDefendant.Text = english.SelectSingleNode("APP").InnerText;
lblCaseConcludedDate.Text = english.SelectSingleNode("casecon").InnerText;
lblGenBy.Text = english.SelectSingleNode("GENBY").InnerText;
lblRID.Text = english.SelectSingleNode("RptID").InnerText;
txtRID.Text = english.SelectSingleNode("RID").InnerText;
lblrpt.Text = english.SelectSingleNode("RPT").InnerText;
lblRunDt.Text = english.SelectSingleNode("RNDT").InnerText;
lblCaseNo.Text = english.SelectSingleNode("CSNO").InnerText;
lblDateOfFilingCase.Text = english.SelectSingleNode("Fil").InnerText;
lblDptment.Text = english.SelectSingleNode("Dept").InnerText;
lblSection.Text = english.SelectSingleNode("Sec").InnerText;
lblCheckedBy.Text = english.SelectSingleNode("CheckedBy").InnerText;
}
}
}
}
}




Author: vijayendra krishna salunkhe    04 Aug 2008Member Level: BronzeRating:     Points: 0
Thank you Arjun



Post Reply
You must Sign In to post a response.
Next : accesing xml data source
Previous : Anybody there
Return to Discussion Forum
Post New Message
Category: XML

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

efax

Contact Us    Privacy Policy    Terms Of Use