Showing posts from September, 2010

Be Careful When Using xmlDom.getElementsByTagName

If you are working with PL/SQL XML DOM API, searching for elements using xmldom.getElementsByTagName may dramatically affect the performance of your code, especially if you are dealing with big XML Documents. Instead of searching for the same element over and over again, you should cache the node returned by xmldom.getElementsByTagName API and use the cached reference in subsequent DOM operations.

In the code below, new elements are added to an XML Document. We get the parent node with xmldom.getElementsByTagName API. In the first example, we get the parent node each time when a new node is added. The code executes in 0.27 seconds. In the second example, we find the parent node only once and reuse it. The same operation now takes only 0.05 seconds.

package test_xml
exec test_xml.initxml; / select test_xml.getxmltype from dual / -- add new action elements (slow way) declare v_doc_xml xmldom.domdocument; v_newActionElement_xml xmldom.domelement; v_newActionNode_xml xmldom.…