problem of python whitespace XML dom

Discussion in 'Python' started by admod, Jan 13, 2016.

  1. admod

    admod

    Joined:
    Jan 13, 2016
    Messages:
    1
    Likes Received:
    0
    Dear Friends,
    I am using the minidom for my python application. But the problem is that the whitespace in XML document .

    My code calling the function is
    Code (Text):
    def mostrar_libro(self, lista):  # show_book
          """
          Method for displaying a book on screen when you load the DBR
          """

          self.limpiar_modelo()  # clean_model
          l = []
          for x in range(len(lista)):
              try:
                  #y = lista[x].childNodes
                  cleanUpNodes(lista[x])
                  y = lista[x].childNodes
                  #y = self.cleanUpNodes(lista[x])
                  #print "y hahaha is: "+y[0].toprettyxml()
                  z = y[0].firstChild.toprettyxml()
                  print "data yo yo  is "+z
                  l.append(y[0])
              except AttributeError:
                  pass
              iter = self.treestore.append(None, ['%s' % z])
    The called function is

    Code (Text):
    def remove_whilespace_nodes(node):
          """ Removes all of the whitespace-only text decendants of a DOM node. """
          # prepare the list of text nodes to remove (and recurse when needed)
          #global dom
          remove_list = []
          for child in node:
              if child.nodeType == node.TEXT_NODE and not child.data.strip( ):
                  # add this text node to the to-be-removed list
                  remove_list.append(child)
              elif child.hasChildNodes( ):
                  # recurse, it's the simplest way to deal with the subtree
                  remove_whilespace_nodes(child)
              # perform the removals
          for node in remove_list:
              node.parentNode.removeChild(node)
              node.unlink( )
    but got error as

    Please advise with a quick solution

    Thanks
    Anes
     
    admod, Jan 13, 2016
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Oli Filth
    Replies:
    9
    Views:
    3,768
    Uncle Pirate
    Jan 17, 2005
  2. manjunath.d@gmail.com

    Convert a XML DOM Object to a HTML DOM Object

    manjunath.d@gmail.com, Sep 20, 2005, in forum: XML
    Replies:
    0
    Views:
    823
    manjunath.d@gmail.com
    Sep 20, 2005
  3. aine_canby@yahoo.com

    Replacing _xmlplus.dom.minidom with xml.dom.minidom

    aine_canby@yahoo.com, Aug 3, 2007, in forum: Python
    Replies:
    3
    Views:
    897
    Stefan Behnel
    Aug 3, 2007
  4. Water Cooler v2
    Replies:
    0
    Views:
    557
    Water Cooler v2
    Nov 2, 2007
  5. Water Cooler v2
    Replies:
    1
    Views:
    1,430
    Martin Honnen
    Nov 2, 2007
  6. Alan
    Replies:
    6
    Views:
    2,217
  7. cmdrrickhunter@yaho.com

    Structure using whitespace vs logical whitespace

    cmdrrickhunter@yaho.com, Dec 15, 2008, in forum: Python
    Replies:
    10
    Views:
    1,177
    Eric Brunel
    Dec 16, 2008
  8. MRAB
    Replies:
    3
    Views:
    713
Loading...