Visual Basic Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

VB Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
RSA Encryption
S/MIME
Socket
Spider
String
Tar
Unicode
Upload
XML
XMP
Zip Compression

More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor


VB Strings
VB Byte Array

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

 

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-2008 Chilkat Software, Inc. All Rights Reserved.