Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • A friend and I had a similar discussion about generating XML in a simple way today -- we trawled CPAN and found XML::Generator [cpan.org]. Does it do (most of) what you're looking for?

    • I had looked at XML::Generator and I liked it, but it had some problems. First, because of autoload, it's easy to do this:

      print $xml->feild('foobared');

      I probably meant "field". My version forces you to map methods to tags and will die if you try to print a tag that doesn't exist (though you can add methods/tags on the fly).

      Also, as far as I can tell, I would not be able to conveniently dump out data in the Yahoo! IDIF format. Here's an snippet:

      <?xml version="1.0"?>
      <IDIF>
       

      • by foobah (7270) on 2007.06.24 12:37 (#55739)

        Also, as far as I can tell, I would not be able to conveniently dump out data in the Yahoo! IDIF format. Here's an snippet:

        That is not even remotely well-formed XML (note the unclosed "br" tags, for example), but it's perfectly valid for Yahoo!'s IDIF format. Trying to produce a bunch of stuff like this with most XML modules is what finally led me to start writing my own. From what I can see, XML::Generator will not allow me to write that.
        I'm sure the usefulness of this information is long gone for you, but XML::Generator was designed to allow generation of invalid XML when necessary. You just didn't look hard enough... ;-)

        use XML::Generator ();

        my $idif = XML::Generator->new(pretty => 2, conformance => 'strict');
        my $ugly = XML::Generator->new(escape => 'unescaped', empty => 'ignore');

        print
        $idif->xml(
          $idif->IDIF(
            $idif->DOC({url=>"http://www.example.com/radio/2005/09/28/fall05_voll11_2"},
              $idif->CONTENT({type=>"text/html"},
                $idif->html(
                  $idif->head(
                    $idif->title("Volume 11 Fall 2005: Show 2"),
                  ),
                  $idif->body(
                    $ugly->hi("Volume 11 Fall 2005"),
                    $ugly->br(),
                    "\nHi there!  This is bad XML \&-/\n",
                    $ugly->br(),
                  ),
                ),
              ),
            ),
          ),
        );