Passing XML object versus filling structure

ActionScript 3.0 has decent native XML support, so I'm not surprised to see many people load external XML and then pass the object to various modules / sections of code.

However, my instinct is to create a class (i.e. with statically named / typed fields), populate it from XML, and pass it there. The advantage is to decouple the structure from the message / data format, but you lose the XML searchability, and if you have a lot of nested structures I can see how it can take a lot of initial processing time to transform it.

So what's the best thing here? For really small projects / use cases, I still just use XML, but when it gets bigger, or I have some foresight, I tend to go the class route.

+1


source to share


4 answers


Finally, my preferred solution is to populate the classes from data, but keep the XML reference somewhere whenever I need a search capability.



0


source


I would say that due to the fact that the XML object has no static structure, it opens up a lot of room for creep errors in systems, and also makes the code much less comprehensible and understandable.

So, I would say yes, class is the way to go, it's an extra effort, but because of that, your system is a lot structured.

I've experimented with wrapping classes around XML objects in the past, but that can make the code inside those classes quite messy.



I am currently experimenting with binding XML objects to objects using the XMLObjectBinder class I wrote (pure actionscript projects, not Flex) as I find this approach the cleanest since XML comes out of the picture as soon as possible. This way my classes are now cleaner due to the lack of XML inside them and the binding is usually a one-line call from the factory.

On the question of looking for opportunities, I agree that you will lose this, but I would say that the factory pattern combined with XML binding to an object will remove many of these problems.

+1


source


I tend to create "reader" classes that load data and store it in their own XML object. Then I pass any data from XML to other objects as native types.

0


source


I can't speak ActionScript, but I think the experience I had in VB6 and C # might make a difference:

XML message format changes. When they do this, the code that is closely related to the message format breaks. If you can keep all of your XML interacting code in one place, you can harm your application by modifying the message format. Building objects outside of XML and then using objects in your code keeps most of your code separate from changes to the message format.

There are many applications where this is not very dangerous - where, for example, it is OK to associate the logical structure of the code with the structure of the XML, since XML reflects the logical structure of the application domain.Therefore, you must use some judgment when deciding which approach to take.

0


source







All Articles