I usually had a finite number of xml's 4 or 5 per project top. So I wrote 
custom parsers/unmarshallers and use e4x. Works like clockwork :)

C




________________________________
From: W.R. de Boer <w...@innerfuse.biz>
To: flexcoders@yahoogroups.com
Sent: Tue, February 9, 2010 4:02:54 PM
Subject: [flexcoders] Best practices regarding XML to VO conversion

   
Hello,

I am having a question what the best approach is to convert existing XML data 
to a object graph of value objects. I have spend quite some time to fix a 
memory leak in my existing parsing practice and I am curious how others solve 
this problem.

My common approach is to create a class such as EventReader and EventItemReader 
class which is responsible for the parsing of the specific XML element and 
return the appropriate value object. But somehow this code is leaking like a 
mad dog (200kb per time) while the XML file is only 16kb. Now I have currently 
rewritten it so that just using simple strong typed objects. 

But I would love to find out what I am doing wrong in my current approach and 
how to solve it. Because it makes it easier to reuse the parsing code/logic. 

For example, normally, I use the approach of creating a public class with a few 
public variables like this:

public class EventItemVO {
public var eventDate: Date;
public var eventName: String;
public var location: String;
}

and then I am having code like this to parse it:

try {
var xml: XML = new XML( loaderContent );
var parser: EventItemXMLReader = new EventItemXMLReader( xml );
parser.parse( );
} catch (e: Error) {
trace("Error occured while parsing");
} finally {
parser = null;
xml = null;
}

in the EventItemXMLReader- class I then return an instance of the EventItemVO- 
class

Somehow this leaks and while I do the same stuff in the onComplete-handler of 
the Loader and do:
array.push( {eventDate:date, eventName:name, location:location} );

The memory leak disappears. I would expect their is some reference kept alive 
but I am having a hard-time finding the reference which keeps it from garbage 
collecting it all.

How do you parse XML and convert it in value objects?

Yours,
Weyert de Boer
 


      

Reply via email to