Click here to Skip to main content
6,295,667 members and growing! (9,484 online)
Email Password   helpLost your password?
Languages » C / C++ Language » General     Intermediate

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

By G. Kiran

A 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
Posted:11 Oct 2006
Views:11,287
Bookmarked:6 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
7 votes for this article.
Popularity: 1.56 Rating: 1.84 out of 5
3 votes, 42.9%
1
1 vote, 14.3%
2

3

4
3 votes, 42.9%
5

Introduction

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

G. Kiran


Member
I have been working as Application Engineer for 2+ years in ASP.NET
Occupation: Web Developer
Location: India India

Other popular C / C++ Language articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin 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