are you sure that "name" always come earlier than "points", "polylines", etc in a file?  If not, "name" should be searched independently at the beginning and then other tags can be parsed.