Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Delete XML Nodes in Visual BasicSource 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.