Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Loop Over XML Records in Visual BasicSource Code Listing ' This example requires Chilkat XML v3.0.0
' Iterate over each "DOC" record and copy the
' ArticleTitle to a new XML document
Private Sub Command2_Click()
Label2.Caption = "Working..."
Label2.Refresh
Dim xml As ChilkatXml
Dim outXml As New ChilkatXml
' Load the input document.
Set xml = New ChilkatXml
xml.LoadXmlFile "crisp.xml"
' Create the output XML document in-memory
outXml.Tag = "article_titles"
' Iterate over the "DOC" nodes by calling FirstChild2
' followed by NextSibling2 repeatedly until it returns false.
' Calling FirstChild2 updates our internal reference to the first child.
If (xml.FirstChild2() = 0) Then
Set xml = Nothing
End If
' Note: if "xml" is Dim'med as "New ChilkatXml" then this loop will never exit.
' Be sure to Dim it without "new"
Do While Not (xml Is Nothing)
' FindChild2 updates our internal reference to the found child.
If (xml.FindChild2("ArticleTitle") = 1) Then
' NewChild returns the created child, whereas NewChild2 does not.
outXml.NewChild2 "article", xml.Content
' Restore our internal reference back to the parent.
xml.GetParent2
End If
' 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 (xml.NextSibling2() = 0) Then
Set xml = Nothing
End If
Loop
outXml.SaveXml "ArticleTitles2.xml"
Label2.Caption = "Done."
End Sub
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.