You should never call the same method twice if you can help it.  Call `node.getElementsByTagName('begin')` once and store the result in a variable.  Same for anywhere else you have code like this.