Document guidelines for getElementsByTagNameNS and optimize all usages

Adds documentation as requested. Fixed #736.