![]() |
Languages »
C / C++ Language »
General
Intermediate
Check if an XmlNode is a child node in an XML DOM treeBy G. KiranA recursive procedure to check if an XML node is a child node of another XML node in an XML DOM tree. |
VB, XML, Windows, .NET 1.0, .NET 1.1, .NET 2.0, Visual Studio, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||
This article describes a simple procedure to check if a given node is a child node of another node. The XML DOM tree consists of a number of XML nodes. If it is required to check if a node in an XML DOM tree is a child node of the same tree, use the simple procedure shown below. The procedure is a recursive one.
The checkNode is type of XmlNode used to check whether the node is a child node of parentNode of type XmlNode. Make sure that both are in the same XmlDocument. Otherwise it always returns False.
Public Function IsCheckNodeChildNodeOfParentNode(ByRef parentNode _
As XmlNode, ByRef checkNode As XmlNode) As Boolean
Try
Dim xNode As XmlNode
If checkNode Is parentNode Then
Return True
ElseIf parentNode.HasChildNodes Then
For Each xNode In parentNode.ChildNodes
If checkNode Is xNode Then
Return True
Else
If IsCheckNodeChildNodeOfParentNode(xNode, _
checkNode) Then
Return True
End If
End If
Next
Else
Return False
End If
Return False
Catch ex As Exception
Throw New Exception(ex.Message & " " & ex.StackTrace)
End Try
End Function
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 11 Oct 2006 Editor: Smitha Vijayan |
Copyright 2006 by G. Kiran Everything else Copyright © CodeProject, 1999-2009 Web16 | Advertise on the Code Project |