Xbase++
Xbase++
Demonstrate XML SearchForTag2
Demonstrates how to use SearchForTag2.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oXml
LOCAL i
LOCAL oXmlSearch
LOCAL oAfterPtr
LOCAL oPTemp
LOCAL oSbState
nSuccess := 0
oXml := CreateObject("Chilkat.Xml")
// Load the following XML:
// <Test>
// <testchild1>
// test
// </testchild1>
// <testchild1>
// test1
// </testchild1>
// <testchild1>
// test2
// </testchild1>
// <testchild1>
// test3
// </testchild1>
// <testchild1>
// test4
// </testchild1>
// <testchild1>
// test5
// </testchild1>
// <testchild1>
// test6
// </testchild1>
// </Test>
nSuccess := oXml:LoadXml("<Test><testchild1>test</testchild1><testchild1>test1</testchild1><testchild1>test2</testchild1><testchild1>test3</testchild1><testchild1>test4</testchild1><testchild1>test5</testchild1><testchild1>test6</testchild1></Test>")
i := 0
oXmlSearch := oXml:GetRoot()
oAfterPtr := oXml:GetRoot()
// Alway begin the search from the root.
DO WHILE oXmlSearch:SearchForTag2(oAfterPtr, "testchild1")
// If successful, xmlSearch now points to the found element.
i := i + 1
// Set afterPtr = xmlSearch (so we find the next match after the one we just found)
// Rest xmlSearch to the root of the XML tree to be searched.
? Str(i) + ": " + oXmlSearch:Content
oPTemp := oAfterPtr
oAfterPtr := oXmlSearch
oPTemp:GetRoot2()
oXmlSearch := oPTemp
ENDDO
oXmlSearch:destroy()
oAfterPtr:destroy()
? "----"
// A better way:
oSbState := CreateObject("Chilkat.StringBuilder")
i := 0
DO WHILE oXml:NextInTraversal2(oSbState) != 0
IF (oXml:TagEquals("testchild1") == 1)
? Str(i) + ": " + oXml:Content
i := i + 1
ENDIF
ENDDO
oXml:GetRoot2()
oXml:destroy()
oSbState:destroy()