FAQ
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


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

Search Discussions

  • Ivan Herman at Aug 14, 2004 at 1:27 pm
    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


    Ajay wrote:
    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


    ----------------------------------------------------------------
    This message was sent using IMP, the Internet Messaging Program.
  • Tim Arnold at Aug 16, 2004 at 11:45 am
    "Ajay" <abra9823 at mail.usyd.edu.au> wrote in message
    news:mailman.1651.1092488767.5135.python-list at python.org...
    str = whiteSpaces[counter].nodeValue
    string.strip(str) <snip>
    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 14, '04 at 1:06p
activeAug 16, '04 at 11:45a
posts3
users3
websitepython.org

3 users in discussion

Ajay: 1 post Ivan Herman: 1 post Tim Arnold: 1 post

People

Translate

site design / logo © 2022 Grokbase