problem of python whitespace XML dom

Joined
Jan 13, 2016
Messages
1
Reaction score
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:
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:
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

self.mostrar_libro(lista)
File "/usr/local/lib/python2.7/site-packages/dbr/vista.py", line 194, in mostrar_libro
remove_whilespace_nodes(lista[x].childNodes)
NameError: global name 'remove_whilespace_nodes' is not defined

Please advise with a quick solution

Thanks
Anes
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top