A quick comment on the 'node tree' idea...
Oscar Rambla wrote:
>>Well, if we can maintain the tree structure, and if you have access to
>>each node's name, attributes and children, then you should be able to
>>transform the tree. If I needed to do a lot of this kind of thing, I
>>would probably use another tool, but perhaps there are some simple,
>>common cases that we should facilitate. Some use-cases would be helpful.
>>I would hesitate to do /too/ much of this, or we will begin to
>>reinvent existing XML technologies.
>
> I didn't pretend you to do it , in any way. Maintain the tree structure would
> be enough for me. If I needed to do a lot of things I could translate it to a
> well-proven XML tool. Sorry but I don't see the way to maintain it with the
> current version.
Here's a quick example. You can tell from the code that I did not design
it for easy tree manipulations -- but it is possible!
# given a list of four LI elements,
# insert a new element at the second position, and
# remove the "dummy" elements
from nevow import *
mylist = ul[
li['first point'],
li['last point'],
li(id='dummy1')['dummy point 1'],
li(id='dummy2')['dummy point 2'],
]
mylist.content.lst.insert(1, li['inserted point'])
for item in mylist.content.lst[:]:
if item.attribs.get('id', '').startswith('dummy'):
mylist.content.lst.remove(item)
print mylist
which prints (without the newlines):
- first point
- inserted point
- last point
With a little work we could clean this up, and it could look like:
mylist.children.insert(1, li['inserted point'])
for item in mylist.children[:]:
if item.attribs.get('id', '').startswith('dummy'):
mylist.children.remove(item)
which is a bit more DOM-like.
* * * * * *
By the way, there is a tiny error in my nevow.py file. I assume that
those of you who tried it found the bug and fixed it yourselves. If you
get an error like:
File "
", line 1
= Tag("")
^
SyntaxError: invalid syntax
add the following lines:
for tagname in tagnames.split(' '):
+ if tagname:
.... cmd = '%s = Tag("%s")' % (tagname, tagname)
.... exec cmd
or strip out the extra space at the end of the 'tagnames' variable.
-- Graham