Besides LINQ-to-XML, you can also use XpathNavigator class to navigate into your xml. I have written a sample block for you. Please have a look, may be helpful..
protected string SearchChildNodeByParentNode()
{
string output = String.Empty;
XmlDocument _ObjXmldocument = new XmlDocument();
_ObjXmldocument.Load(Server.MapPath("~/XML/GetChild NodeByParent.xml"));
XPathNavigator _objXpathNavigator = _ObjXmldocument.CreateNavigator();
_objXpathNavigator.MoveToRoot();
_objXpathNavigator.MoveToFirstChild();
do
{
if (_objXpathNavigator.NodeType == XPathNodeType.Element)
{
if (_objXpathNavigator.HasChildren)
{
_objXpathNavigator.MoveToFirstChild();
output += _objXpathNavigator.Name + " ";
}
}
} while (_objXpathNavigator.MoveToNext());
return output;
}
Please "Mark As Answer;", if this Post helps you.
Visit My Blog
kuber.manral
Contributor
3051 Points
714 Posts
Re: Elements in Xml
Mar 23, 2012 06:03 AM|LINK
Hi Madha Dhanasekar,
Besides LINQ-to-XML, you can also use XpathNavigator class to navigate into your xml. I have written a sample block for you. Please have a look, may be helpful..
protected string SearchChildNodeByParentNode() { string output = String.Empty; XmlDocument _ObjXmldocument = new XmlDocument(); _ObjXmldocument.Load(Server.MapPath("~/XML/GetChild NodeByParent.xml")); XPathNavigator _objXpathNavigator = _ObjXmldocument.CreateNavigator(); _objXpathNavigator.MoveToRoot(); _objXpathNavigator.MoveToFirstChild(); do { if (_objXpathNavigator.NodeType == XPathNodeType.Element) { if (_objXpathNavigator.HasChildren) { _objXpathNavigator.MoveToFirstChild(); output += _objXpathNavigator.Name + " "; } } } while (_objXpathNavigator.MoveToNext()); return output; }Visit My Blog