[XML-SIG] Removing insignificant whitespace

Thomas B. Passin tpassin at comcast.net
Tue Aug 31 22:33:51 CEST 2004


Brian Quinlan wrote:

> I'm trying to remove the whitespace-only text nodes in my XML DOM. I've 
> tried two approaches:
> 
> 1. StripXml - generates a an exception:
> 
>   File "mac.py", line 25, in __init__
>     StripXml(self.document)
>   File "/usr/lib/python2.3/site-packages/_xmlplus/dom/ext/__init__.py", 
> line 153, in StripXml
>     snit = owner_doc.createNodeIterator(startNode, NodeFilter.SHOW_TEXT,
> AttributeError: Document instance has no attribute 'createNodeIterator'
> 
> 2. setFeature('whitespace_in_element_content', False) seems to do
>    nothing
> 
> My code is here:
> 
> from xml import xpath, dom
> from xml.dom.ext import StripXml
> from xml.dom.xmlbuilder import DOMInputSource, DOMBuilder
> from optparse import OptionParser
> from pprint import pprint
> import os
> 
> b = DOMBuilder()
> b.setFeature('whitespace_in_element_content', False)
> self.document = b.parse(...)
> StripXml(self.document)
> 
> My XML does not include a DTD or any declarations regarding whitespace. 
>  Can anyone offer any advice?

What's wrong with normalize()?

Cheers,

Tom P
-- 
Thomas B. Passin
Explorer's Guide to the Semantic Web (Manning Books)
http://www.manning.com/catalog/view.php?book=passin


More information about the XML-SIG mailing list