Ever since XML handling in
Java started, very skilled people have labored on making the libraries more efficient.
Why do you think re-inventing the wheel (or the DOM) is a good idea?
Back off a couple of kilometers and try to state your problem in a general way without preconceived technology notions. You might be surprised at how easy the solution turns out to be.
Bill