[XML-SIG] no 'writexml' when building a domTree from ext.Sax2

Uche Ogbuji uche.ogbuji at fourthought.com
Thu Jul 29 21:34:02 CEST 2004


On Thu, 2004-07-29 at 02:55, Alexandre CONRAD wrote: 
> >>My idea here is to :
> >>1- read an xml file
> >>2- make modifications to it (delete nodes)
> >>3- save it back to a file
> >>
> >>The way I build my DOM tree is with :
> >>
> >>     from xml.dom.ext.reader import Sax2
> > 
> > 
> > Why do you think you need to do this?  Are you sure you don't want plain
> > old minidom?  For one thing, you're looking for minidom APIs on a 4DOM
> > instance (well, almost: it's toxml() on minidom, not writexml() ).
> 
> Well, simply because on the official documentation says so :
> http://pyxml.sourceforge.net/topics/howto/node18.html

Honestly, most of the pyxml HOWTO is out of date.  The Akara is my own
attempt to accumulate docs that are not out of date (or at least flag
when they are):

http://uche.ogbuji.net/akara/nodes/2003-01-01/general-section?xslt=/akara/akara.xslt


> And because after that, I need to traverse my tree as explained in the 
> same official documentation here :
> http://pyxml.sourceforge.net/topics/howto/node22.html
> 
> But apparently, minidom doesn't seem to have any createTreeWalker 
> method. I haven't got into it very deep actually. And I'm a newby 
> programmer to.
Do you think you really need treewalker?  If so, you might try using it
on a minidom, cDomlette or pxdom instance.  I don't know whether that
will work.

But more importantly, could your needs be better met using XPath or
other navigational means?


> My project is for generating a video playlist via a web-base interface 
> (mod_python).
Sounds straightforward.


> The originally created XML playlist used as a testing XML file and was 
> done before I got into the web-based stuff. And for generating a 
> playlist from scratch, I just wrote python scripts and used a
>      doc = xml.dom.minidom.Document()
> 
> and do some 'doc.appendChild(child)' for manipulation to build my xml. 
> After that, I saved the file using 'doc.writexml(indent="", newl="")' 
> which let me generate a playlist with no indentation and newline.
> 
> After the XML file is generated on the 'admin side', I send the playlist 
> on the 'player' that is doing a 'createTreeWalker' on the XML file and 
> pass through every node and read videos <video>some_file.mpg</video>. 
> Well, it's a little bit more complicated then that because I handle 
> scheduling and a lot more, but that gives you the big picture.
> 
> That's how I got there. So now, I'm getting my scripts back and adapting 
> them for my web-based application in mod_python to be able to easely 
> make modification to the playlist via a GUI. So now, I'm developping the 
> 'edit playlist' part. So as a player would do, I'd do a
>      reader = Sax2.Reader()
>      doc = reader.fromStream(playlist_file)
> 
> then have a createTreeWalker that would traverse the playlist to display it.
There are so many ways to do all this that I'm not sure where to start. 
What are your priorities?  Speed?  Low memory footprint?  Simplicity of
code? Avoiding installing 3rd-party tools?...


> I haven't got into the question of 'how am I going to create a new 
> playlist file from scratch ?' yet. I'd probably use the 'doc = 
> xml.dom.minidom.Document()'

Be sure to use xml.dom.minidom.getimplementation() and the
createDocumentType()/createDocument() instead.  Do not use constructors
such as Document() and Element() directly.


> and have some traditionnal 
> 'doc.appendChild(child)' to build the 1st element and then save the 
> file. Once the 1st node is written on disk, I'll parse the file again 
> using Sax2 to display it and be able to add more stuff to the playlist.
> 
> > Warning: 4DOM is very slow.  It's claim to fame used to be compliance,
> > but now it has been superseded in that regard by Andrew Clover's pxdom.
> > 
> > I'm pretty sure I wouldn't recommend 4DOM to anyone for anything right
> > now.  
> 
> Well, I'm just reading the documentation. What would you recommand ?

I need much more info.  minidom?  cDomlette?  pxdom?  A Python "data binding"?
An output library?  Many things would work.

Of course, I write a great deal on all these options, and more in my column:

http://www.xml.com/pub/at/24


-- 
Uche Ogbuji                                    Fourthought, Inc.
http://uche.ogbuji.net    http://4Suite.org    http://fourthought.com
Perspective on XML: Steady steps spell success with Google - http://www.adtmag.com/article.asp?id=9663
Use XML namespaces with care - http://www-106.ibm.com/developerworks/xml/library/x-namcar.html
Managing XML libraries - http://www.adtmag.com/article.asp?id=9160
Commentary on "Objects. Encapsulation. XML?" - http://www.adtmag.com/article.asp?id=9090
Harold's Effective XML - http://www.ibm.com/developerworks/xml/library/x-think25.html
A survey of XML standards - http://www-106.ibm.com/developerworks/xml/library/x-stand4/



More information about the XML-SIG mailing list