C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Parsing of XML file using C# .NET


Posted Date: 04 Jun 2004    Resource Type: Articles    Category: .NET Framework
Author: ShajanMember Level: Silver    
Rating: 1 out of 5Points: 5




public string GetXMLValues()
{
string strXML="";
System.Xml.XmlDocument XmlDoc =new System.Xml.XmlDocument();
System.IO.FileInfo objFile=new System.IO.FileInfo(path);
try
{
if (objFile.Exists)
{
XmlDoc.Load(path);
XmlTextReader reader = new XmlTextReader(path);
XmlNodeList nodelst;
nodelst= XmlDoc.GetElementsByTagName("ElementName");
strXML= nodelst.Item(0).InnerText+";";
nodelst = XmlDoc.GetElementsByTagName("ElementName");
strXML+= nodelst.Item(0).InnerText+";";
return strXML;
}
else
{
return "XML File Not Exists";
}

}
catch(Exception ex)
{
return "Error Occured while reading XML File";
}
}




Responses

Author: critic    15 Jun 2004Member Level: Bronze   Points : 0

.NET Classes used :

System.Xml;
System.IO;


Is System.Xml a class ? I thought it is a namespace.



Author: Shashikant Shinde    03 Sep 2004Member Level: Bronze   Points : 0
I have XML file in following format

..............
............
...........

.................
...............
<...> ANY DATA


.................
...............
<...> ANY DATA

How can I access the titles which are under .....
I do not want the title under .....

I am also pasting my snippet , that might help you to solve my query
Thanks
Shash



XmlTextReader xReader = new XmlTextReader(xmlFrag, XmlNodeType.Document, null );
while(xReader.Read())
{
if(xReader.Name.ToLower() == "title")
{
//string oldfile = @"C:\MyOldFile.txt";
string title = xReader.ReadInnerXml();
this.listView2.Items.Add(title);
index++;
this.listView2.Items[index-1].SubItems.AddRange(new string[] {"","","","",""});
//StreamWriter oldsw = File.AppendText(oldfile);
//oldsw.WriteLine(title);
//oldsw.Close();
}
if((xReader.Name.ToLower() == "dc:pubdate") || (xReader.Name.ToLower() == "pubdate") || (xReader.Name.ToLower() == "date") || (xReader.Name.ToLower() == "dc:date") || (xReader.Name.ToLower() == "lastbuilddate") || (xReader.Name.ToLower() == "dc:lastbuilddate"))
{
try
{
string date = xReader.ReadInnerXml();
DateTime dateObj = DateTime.Parse(date);
this.listView2.Items[index-1].SubItems[1].Text = dateObj.ToString();
//row_index Column_index
}
catch
{
//MessageBox.Show(e.ToString());
}
}
}



Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Create XML file using C# .NET (with indentation)
Previous Resource: Using base to Access a Hidden Name
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use