ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
RFC: XML::Composer
by Ovid other posts by this author
Sep 30 2005 2:54PM messages near this date
view in the new Beta List Site
Re: Bug in XML::Writer? | Re: RFC: XML::Composer
& XSLT Hi all,

Yes, I am proposing another XML module.  I just posted a meditation to
Perlmonks: 
http://perlmonks.org/index.pl?displaytype=display;node_id=496522

Text is reproduced below.

Cheers,
Ovid

--

I know many would rather not see another module in the XML namespace,
but I've started putting together a proof of concept called
XML::Composer (it was originally called XML::JFDI with apologies to
Jesse). It will let you write really, really bad XML. It will also
allow you to write XML "variants" like the awful Yahoo! IDIF format.
Namespaces? It doesn't know about 'em or care about 'em. If you want to
use a colon in an attribute name, go ahead. Want to inject an XML
snippet from somewhere else? Go ahead. It will simply do whatever you
tell it to do. It's a sad fact of life that there's a lot of bad XML
"variants" out there that we, as developers, have to live with (maybe
this module should be called XML::Awful).

The primary idea is to be able to write XML in just about any format
you want. Frequently this means that it will cheerfully produce bad
XML, but rather than spend hours scouring the docs only to find
yourself reporting another bug, you can quickly and easily tweak what
you want. Unfortunately, most of the modules in the XML namespace are
geared towards producing correct XML. Sometimes you need to produce bad
XML so you roll your own XML generator and hope no one ever sees it.

The aim of XML::Composer is to make bad XML official. If you have to
produce it, at least you should produce it as easily as possible.

    use XML::Composer;

    my $xml = XML::Composer-> new({
        # tag         method
        'ns:foo'  =>  'foo',
        'bar'     =>  'bar',
        'ns2:baz' =>  'baz',
    });
    $xml-> Decl; # add declaration (optional)
    $xml-> PI('xml-stylesheet', {type => 'text/xsl', href="$xslt_url"});
    $xml-> foo(
        { id =>  3, 'xmlns:ns2' => $url},
        $xml-> bar('silly'),
        $xml-> Comment('this is a > comment'),
        $xml-> Raw('<bad tag>');
        $xml-> baz({'asdf:some_attr' => 'value'}, 'whee!'),
    );
    print $xml-> Out;
    if ($xml-> Validate) { # false for above example
    }
    __END__
    <?xml version="1.0"> 
    <?xml-stylesheet type="text/xsl" href="$xslt_url"?> 
    <ns:foo id="3" xmlns:ns2="$url"> 
      <bar> silly</bar>
      <!-- this is a &gt; comment --> 
      <bad tag> 
      <ns2:baz asdf:some_attr="value"> whee!</ns2:baz>
    </ns:foo> 

This module (not yet on the CPAN) assumes that you, the programmer,
know what you're doing. It's designed for agile development: produce
something quickly but have a test suite to verify that your output is
correct. In short, there is a very specific design philosophy here and
I wouldn't recommend it for those who don't have test suites, but it
makes coding very fast (and no, it doesn't use AUTOLOAD to build those
methods).

Thoughts?

-- 
If this message is a response to a question on a mailing list, please send
follow up questions to the list.

Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Ovid
Benjamin Franz
G. Wade Johnson
Wren Argetlahm
Ovid
Adam Worrall
David Kaufman
Grant McLean
Mark - BLS CTR Thomas
Ovid
Ovid
Bruce Miller
Ovid
Matt Sergeant
Ovid
Matt Sergeant
Ovid
johns
Danny Brian
Ovid

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved