[Doc-SIG] How to traverse a document object
Mon, 22 Oct 2001 20:45:18 +0100
I don't know if I'm missing something stupidly obvious here... I want to
traverse a document generated by a dps.parsers.restructuredtext.Parser
instance. I can see no way of doing so short of a manual tree-walk with
type checks all the way - you know::
if type(current_node) =3D=3D section:
# process a section, probably recursing on its children
elif type(current_node) =3D=3D paragraph:
# process a paragraph
# etc, ad nauseam.
This *can't* be the correct way of doing this. The example code in the
tools directory isn't any help, as it builds on the asdom() method,
which does the trick "for free".
I tried looking at the xml.dom module, but that didn't offer anything
that immediately leapt out at me as a suitable "visitor" interface. But
I'm not familiar with XML, so I'm probably missing something.
But IMHO, there *must* be a simple way of traversing the document model.
At the moment, I can't see it. Can someone enlighten me? (Or if there
isn't one, surely it needs implementing - and as it may well need
support from the classes in nodes.py, I'd imagine it needs adding sooner
rather than later?)
As I say, I'm convinced I've missed something fundamental here...