[VPM] converting objects to/from xml
Darren Duncan
darren at DarrenDuncan.net
Sat Jul 12 19:40:40 CDT 2003
I have another question, mainly for those of you who have worked with XML in Perl.
Given that my SQL::ObjectModel objects are conceptually organized like XML, I would like to make a module which will convert them to XML, and conversely parse an XML document into one of those objects.
I would like to use some suitable modules from CPAN which handle most of the work, but I am unsure of which ones to use. I had tried looking at some SAX modules (which seem common), because a callback interface seems to make sense for parsing XML, but I got the impression that this was perhaps too complicated. Most of the SAX examples I saw didn't have much to do with parsing or generating XML. I want object-oriented modules, and pure perl also, for the moment.
I am wondering whether I would be better off coding this conversion myself, which I would expect is less than 40-100 lines of code, or whether the robustness or wider compatability brought by a CPAN module would be better.
I prefer a simple solution, so I could for example do this:
my $firstxml = "...";
my $objectmodel = SQL::ObjectModel::XML->from_xml( $firstxml );
my $secxml = SQL::ObjectModel::XML->to_xml( $objectmodel );
Then "$firstxml eq $secxml" probably returns true.
The hypothetical SQL::ObjectModel::XML module would have all the references to the CPAN module or alternately home grown implementation internally.
Thanks in advance for any suggestions. -- Darren Duncan
More information about the Victoria-pm
mailing list