xml question

A

Ajay

hi!

i am trying to remove all whitespace elements out of a document.

my code is below

def stripWhiteSpaces(doc):
whiteSpaces = xpath.Evaluate("//text()", doc.documentElement)
counter=0
while(counter< len(whiteSpaces)):
str = whiteSpaces[counter].nodeValue
string.strip(str)
if len(str) == 0:
whiteSpaces[counter].parentNode.removeChild(whiteSpaces[counter])

counter += 1
return doc

however this isn't working. when i print out all the elements in the
document, i still get the whitespace text elements.
what am i doing wrong?

thanks

cheers
 
I

Ivan Herman

I think this is a bug in your python call. AFAIK, 'string.strip(str)'
*returns a copy of a string with stripped whitespace*. Ie, it does not
affect the original string, in this case the nodeValue...

Ivan
 
T

Tim Arnold

Ajay said:
str = whiteSpaces[counter].nodeValue
string.strip(str)
however this isn't working. when i print out all the elements in the
document, i still get the whitespace text elements.

shouldn't str.strip() work instead?
--T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top