On Sun, Oct 15, 2006 at 03:34:00PM +0100, Tristan Hill wrote: > When running the following python script I get spaces left where nodes > have been removed. What am I doing wrong? > > TIA
Tristan - This is a classic misunderstanding of XML parse trees. While the pretty printing is inconsequential to the meaning of the XML, it's still there in the parse tree. If you take a look at the actual parsed tree you've got, there's a bunch of 'text' nodes. Yet there seems to be no text in your document, right? What about all those newlines? That's what you're seeing, the newlines before and after the entry nodes you're removing. See Tip 1 at http://www.xml.com/pub/a/2002/08/14/xpath_tips.html Ross -- Ross Reedstrom, Ph.D. [EMAIL PROTECTED] Research Scientist phone: 713-348-6166 The Connexions Project http://cnx.org fax: 713-348-3665 Rice University MS-375, Houston, TX 77005 GPG Key fingerprint = F023 82C8 9B0E 2CC6 0D8E F888 D3AE 810E 88F0 BEDE > > import libxml2 > > x = libxml2.parseDoc("""\ > <?xml version="1.0" standalone="yes"?> > <rhythmdb version="1.0"> > <entry type="song"> > <location>file:///home/stan/shared/file</location> > </entry> > <entry type="podcast-feed"> > <title>mm</title> > </entry> > <entry type="song"> > <location>file:///home/stan/shared/file</location> > </entry> > <entry type="song"> > <location>file:///home/stan/tmp/file</location> > </entry> > </rhythmdb> > """) > y = x.xpathEval("/rhythmdb/[EMAIL PROTECTED]'song']/location" > "[starts-with(., 'file:///home/stan/shared/')]/parent::*") > for node in y: > node.unlinkNode() > node.freeNode() > x.saveFile("-") > > > > Tristan > > _______________________________________________ > xml mailing list, project page http://xmlsoft.org/ > [email protected] > http://mail.gnome.org/mailman/listinfo/xml _______________________________________________ xml mailing list, project page http://xmlsoft.org/ [email protected] http://mail.gnome.org/mailman/listinfo/xml
