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

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 (here). After that, you can post your question and our members will help you out.