Unfortunately, the file I needed to generate has some 250 lines, and my code is almost a method-for-attribute match. While annoying, not the biggest problem with the code.
The real problem comes when I need to generate the following "looped" section:
XML::Generator can handle that with a simple looping construct wrapped around the calls, i.e.:<imageinfo> <imageurl1>http://www.company.com/images/photo1.jpg</imageurl1> <imagecaption1>Caption 1</imagecaption1> <imageurl2>http://www.company.com/images/photo2.jpg</imageurl2> <imagecaption2>Caption 2</imagecaption2> <imageurl3>http://www.company.com/images/photo3.jpg</imageurl3> <imagecaption3>Caption 3</imagecaption3> <imageurl4>http://www.company.com/images/photo4.jpg</imageurl4> <imagecaption4>Caption 4</imagecaption4> </imageinfo>
This generated fragment is added to a larger document later, via:my $imageSection; foreach my $imageId ( 1 .. 4 ) { my $urlName = "imageurl${imageId}"; my $urlCaption = "imagecaption${imageId}"; $imageSection .= $generator->$urlName(), $imageSection .= $generator->$urlCaption(), }
$generator->imageinfo( $imageSection ),
The problem comes when trying to avoid the native escaping of data. As expected, I can turn off escaping ... but that's not something I feel I should trust. Two generator objects would *help* -- but the larger part of the generation would be forced to *not* use the escaping.
I have a feeling there's a much better way of doing this, and I'd rather discover that now before I spend the next N days fighting with the mappings needed with some of the DB columns ... only to 'discover' a better way of generating this later on ...
In reply to nested loops and escaping in XML::Generator by geektron
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |