If you are frequently parsing XML files in your database, you may find it useful to display a progress bar or message to your user to let them know that something is happening. To do this, you must be able to determine a start point and an end point.
Using this technique, you can count the number of XML elements contained in your XML document, which can be used later for things like progress indicators. In this example, the method is named CountAllElements.
` CountAllElements Method
$child:=Get First XML element($rootElement)
` Here it calls itself. This recursive call allows us to crawl the XML tree.
$child:=Get Next XML element($child)
Supposing we had a file called "test.xml", we could use the following to count elements:
$root:=Parse XML source("test.xml")
The XML document like the following yields a count of 3:
Your only concern is that, since this is a recursive style method, you must make sure to increase your stack size for very large XML files.