[XML-SIG] Ignoring whitespace with DOM

Randall Hopper aa8vb@yahoo.com
Fri, 10 Dec 1999 13:27:35 -0500


--jRHKVT23PllUwdXP
Content-Type: text/plain; charset=us-ascii

I'm new at this so please be gentle.

When building a DOM, all whitespace sequences like newlines and spaces are
turned into nodes in the tree (even those peer to elements).  In Dejanews,
I read that this is required behavior for the parser.

With the Python DOM, is there a supported method to configure whitespace
parsing?  (Possibly something like SAX's ignorableWhitespace which saw
mentioned.)

Or, after parsing, are there methods to "filter out" whitespace nodes?

Or is it expected that you will just selectively ignore certain Text nodes
whenever you are traversing the DOM tree.

Thanks,

-- 
Randall Hopper
aa8vb@yahoo.com

--jRHKVT23PllUwdXP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="elements.py"

#!/usr/bin/env python

from xml.dom import utils,core
import string, sys, StringIO

XML = """\
<?xml version="1.0"?>

<root>
  <element1>Data 1</element1>
  <element2/>
</root>
"""

stream = StringIO.StringIO( XML )

reader = utils.FileReader().readStream( stream )

doc       = reader
rootNode  = doc.documentElement
rootNode2 = doc.childNodes.item(0)
print rootNode
print rootNode2

element1  = rootNode.childNodes.item(0)
element2  = rootNode.childNodes.item(1)
element3  = rootNode.childNodes.item(2)
print element1, element2, element3

--jRHKVT23PllUwdXP--