Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

X-Posted from my use.perl journal (though this meditation is a bit different).

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 easy to write. 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?

Cheers,
Ovid

New address of my CGI Course.


In reply to RFC: XML::Composer by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-24 00:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found