Use stack instead of recursion

This also allows us to work without a local copy of the namespace URIs.