[XML-SIG] memory related issues in Python - bug??

Mallick, Pinki pinki_mallick at mentorg.com
Tue Sep 9 13:01:19 EDT 2003


I think you did not understand my question. What I did works on smaller files, but it does not work in a big file. Let me try to explain it again.

Here is a part of the XML tree I am talking of:

<equation>
	<mi>a</mi>
	<mo>=</mo>
	<mi>y18</mi>
	<mo>*</mo>
	<mi>variable</mi>
</equation>


Here, I am trying to retrieve the string as "a=y18*variable". There is no other node with "y" as its data other than "y18". 

So I am using this method:

def reformat_equation(self, equation_node):
	equation = ""
	equation_grandChildren = equation_node.childNodes
	for grandChildNode in equation_grandChildren:
           equation = equation + str(grandChildNode.firstChild.data)	     
	return equation



Although it returns correct data for all other different nodes in the XML file, only in case of "<mi>y18</mi>", it returns "y" instead of "y18" when the file is very big.

So I think it is something to do with memory handling in Python.

And yes, I tried to use "grandChildNode.firstChild.normalize()" and "grandChildNode.normalize()" as you had suggested, but in both cases it returns "None".

Thanks,
Pinki



-----Original Message-----
From: Fred L. Drake, Jr. [mailto:fdrake at acm.org]
Sent: Tuesday, September 09, 2003 11:30 AM
To: Mallick, Pinki
Cc: 'xml-sig at python.org'
Subject: Re: [XML-SIG] memory related issues in Python - bug??



Mallick, Pinki writes:
 > This works properly for all files. But when I am trying to use it
 > on a very large XML file, one of the node's data is
 > incomplete. eg. if grandChildNode.toxml() returns "<mi>y18</mi>"
 > for this node, then "str(grandChildNode.firstChild.data)" returns
 > only "y" instead of "y18".

Have you checked how many children grandChildNode has?  It's entirely
possible that there are multiple children of grandChildNode, and the
first really does only have "y" as data.  (If in doubt, call
grandChildNode.normalize() first; that should combine adjacent text
nodes.)

 > This looks like some memory problem. Is there any workaround for
 > this problem.

I don't know what else you've done with the tree, but it sounds like
it may simply be a common misunderstanding of the DOM interface.


  -Fred

-- 
Fred L. Drake, Jr.  <fdrake at acm.org>
PythonLabs at Zope Corporation

_______________________________________________
XML-SIG maillist  -  XML-SIG at python.org
http://mail.python.org/mailman/listinfo/xml-sig



More information about the XML-SIG mailing list