Andrew --
Parsing XML is complicated by all sorts of little ugly details, which is why there are a number of standard APIs for XML parsers, and a multitude of available XML parsers that do the whole job for you. For an extremely,
extremely simple document, you might be able to justify doing it by hand, but given what you describe, I hope you're instead using an existing parser, and you're simply asking us about recursively examining the parser's output (a DOM tree, for example.)
See
here if you're not sure what I'm talking about.