Click here to Skip to main content
13,301,510 members (91,702 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked
Posted 11 Oct 2006

Check if an XmlNode is a child node in an XML DOM tree

, 11 Oct 2006
Rate this:
Please Sign up or sign in to vote.
A recursive procedure to check if an XML node is a child node of another XML node in an XML DOM tree.


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 of type XmlNode, and is 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

        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
                    If IsCheckNodeChildNodeOfParentNode(xNode, _
                                                 checkNode) Then
                        Return True
                    End If
                End If
            Return False
        End If
        Return False
    Catch ex As Exception
        Throw New Exception(ex.Message & " " & ex.StackTrace)
    End Try
End Function


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

G. Kiran
Web Developer
India India
I have been working as Application Engineer for 2+ years in ASP.NET

You may also be interested in...

Comments and Discussions

GeneralMy vote of 1 Pin
Rajesh Anuhya5-Mar-12 21:53
memberRajesh Anuhya5-Mar-12 21:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 12 Oct 2006
Article Copyright 2006 by G. Kiran
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid