Visual Basic Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

VB Examples

Bounced Mail
Bz2
Character Encoding
CSV
Digital Certificates
Digital Signatures
Email
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
POP3
RSA
S/MIME
SFTP
SMTP
Socket
Spider
SSH
SSH Key
SSH Tunnel
String
Tar
Unicode
Upload
XML
XMP
Zip Compression

More Examples...
Email Object
DKIM / DomainKey
NTLM
DH Key Exchange
DSA
FileAccess
RSS
Atom
Self-Extractor
Service
Bzip2
PPMD
Deflate
LZW


VB Strings
VB Byte Array

 

 

 

 

 

 

 

Delete XML Nodes in Visual Basic

Download Chilkat XML ActiveX

Source Code Listing

' Delete Keyword nodes from the XML Document, and
' add them to a new document without duplicates.
Private Sub Command4_Click()
    Label4.Caption = "Working... (this test takes a bit longer...)"
    Label4.Refresh
    
    Dim xml As New ChilkatXml
    Dim outXml As New ChilkatXml
    Dim node As ChilkatXml
    Dim kNode As ChilkatXml
    Dim tempNode As ChilkatXml

    ' Load the input document.
    xml.LoadXmlFile "crisp.xml"

    ' Create the output XML document in-memory
    outXml.Tag = "unique_keywords"

    ' Iterate over the "DOC" nodes by calling FirstChild
    ' followed by NextSibling2 repeatedly until it returns false.
    Set node = xml.FirstChild()
    Do While Not (node Is Nothing)
    
        ' Iterate over the Keyword nodes, remove each, and add it to
        ' our new XML document. (Note that the search happens at the
        ' subtree rooted at our current node, and not the entire XML document.)
        Set kNode = node.SearchForTag(Nothing, "Keyword")
        Do While Not (kNode Is Nothing)
      
            ' Does the keyword already exist in the output document?
            If (outXml.SearchForContent(Nothing, "keyword", kNode.Content) Is Nothing) Then
                outXml.NewChild2 "keyword", kNode.Content
            End If

            Set tempNode = kNode
            Set kNode = node.SearchForTag(kNode, "Keyword")

            ' Remove the keyword that was just processed from the XML document.
            tempNode.RemoveFromTree
        
        Loop

        ' Move to the next sibling. The internal reference within node is updated
        ' to the node"s next sibling. If no siblings remain, it returns 0.
        If (node.NextSibling2() = 0) Then
            Set node = Nothing
        End If
    Loop

    ' Sort the output by content (ascending)
    outXml.SortByContent 1

    ' Save the unique keywords.
    outXml.SaveXml "UniqueKeywords.xml"

    ' Save the original document with all the keywords removed.
    xml.SaveXml "KeywordsRemoved.xml"
    
    Label4.Caption = "Done."

End Sub

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.