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 data [DOM traversal]


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




XmlDocument xDoc=new XmlDocument(); //create an instance of the XML Document
try
{
xDoc.Load(path); //get the XML data from the file
XmlNode XNodeParentNode= xDoc.SelectSingleNode("//ParentNodeName"); //start - parsing the XML data //Get the parent Node

int NodeCnt=0;
int ChildNodeCnt=0;
int SuperChildNodeCnt=0;

XmlNode XNodeChildNode;
XmlNode XNodeSuperChildNode;
//traverse all the child nodes of the selected parent node
for(NodeCnt=0;NodeCnt<XNodeParentNode.ChildNodes.Count;NodeCnt++)
{
XNodeChildNode=XNodeParentNode.ChildNodes.Item(NodeCnt);
//this is the immediate child nodes
//do something
Response.Write(XNodeChildNode.Attributes.Item(2).Value);
//getting the attribute value of the child node at a given index
if(XNodeChildNode.Attributes.Item(3).Value=="0")
{
//checking for some value
XNodeSuperChildNode=XNodeChildNode.ChildNodes.Item(0);
//this is the second level child nodes of the selected parent node
if(XNodeSuperChildNode.Attributes.Item(3).Value!="1")
{
//do some thing
Response.Write("<font color=red>*</font>");
}
}
for(ChildNodeCnt=0;ChildNodeCnt<XNodeParentNode.ChildNodes.Count;ChildNodeCnt++)
{
XNodeSuperChildNode=XNodeChildNode.ChildNodes.Item(ChildNodeCnt);
//this is the superchild nodes of the selected parent node

//do something
Response.Write(XNodeSuperChildNode.Attributes.Item(2).Value);
}
}
}
catch(Exception ex)
{
//error trapping code
}





Responses

Author: critic    15 Jun 2004Member Level: Bronze   Points : 0
Article without proper description is not acceptible. If you are submitting code snippets, you must explain the code with proper description. Alos, the subtitle of the article is not descriptive.


Author: Debopriyo Das    05 Aug 2004Member Level: Bronze   Points : 0
The code snippet needs proper documentation. It seems to be incomplete code snippet. Any code presented should be complete, easy to understand and properly documented, so that any one can understand the program.


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: Open File (database) using OpenFileDialog & Save (New) File using SaveFileDialog component
Previous Resource: How to find difference between two Dates in C# or VB.NET ?
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