Re: [xml] unlinking nodes leaves spaces

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?


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


Ross Reedstrom, Ph.D.                                 reedstrm rice edu
Research Scientist                                  phone: 713-348-6166
The Connexions Project            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">
  <entry type="podcast-feed">
  <entry type="song">
  <entry type="song">
y = x.xpathEval("/rhythmdb/entry[ type='song']/location"
    "[starts-with(., 'file:///home/stan/shared/')]/parent::*")
for node in y:


xml mailing list, project page
xml gnome org

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]