[XML-SIG] Simple DOM API a la dom4j/jdom

Martin v. Loewis martin@v.loewis.de
17 Jul 2002 07:10:03 +0200


Gerhard H=E4ring <haering_python@gmx.de> writes:

> It's apparently included PyXML 0.7.1, but not documented at all, AFAIC.

For the moment, I'd recommend to use the XPath implementation that
comes with 4Suite.

> Now this leads me to another question. I noticed that with DOM, I can
> only query specific elements, as there's no method like
> getAllElements(). I really have to use SAX if I want this, right?

No. I'd recommend to write a simple recursive function, or use an
XPath expression ("*" is the XPath expression for that, I believe).

The recursive function would be something like

def getAllElements(node):
  result  =3D [node]
  for c node.childNodes:
    if c.nodeType =3D=3D Node.ELEMENT_NODE:
      result.extend(getAllElements(c)
  return result

> Does anybody know if the XML spec says anything about the order of
> elements? Does the DOM API guarantee to return them in the same order as
> they're encountered in the XML file?

Certainly.

> Lack of a getAllElements() function makes my XML look like:

I'm not quite sure I understand the problem; in any case, it seems
wrong to design the document type based on the processing algorithms
that you can implement.

Regards,
Martin