python xml dom help please
spam.meplease at ntlworld.com
Fri Nov 28 21:59:09 CET 2003
and-google at doxdesk.com (Andrew Clover) wrote in message news:<2c60a528.0311261642.5478397d at posting.google.com>...
> > def appendToDescendant(node):
> > walker.previousSibling()
> > while 1:
> > if walker.currentNode.hasChildNodes():
> > next = walker.nextNode()
> > else: break
> > walker.currentNode.appendChild(node)
> Are you sure this is doing what you want? A TreeWalker's nextNode() method
> goes to an node's next matching sibling, not into its children. To go into
> the matching children you'd use TreeWalker.firstChild().
> I'm not wholly sure I understand the problem you're trying to solve.
actually i'm trying to change the relationship 'is next sibling of' to
'is child of' throughout a document
my latest idea is to go to the end of the document, then walk it
backwards (for christmas?:-) towards this end i wrote:
walker = doc.createTreeWalker(doc.documentElement,NodeFilter.SHOW_ELEMENT,
print '1 '+walker.currentNode.nodeName
next = walker.nextNode()
if next is None: break
print '2 '+walker.currentNode.nodeName
<?xml version="1.0" encoding="utf-8"?>
foiled again. How come the current node is back at the start atfter
the loop has finished?
More information about the Python-list