0
XML::Writer::Simple

                  Alberto Sim˜es
                             o
                  ambs@cpan.org


   ...
Why?




XML wasn’t designed to be written manually;
So, we normally generate XML;
But then, we need to write it          ...
Typical Java Code




System.out.println(quot; <agenda>quot;);
while(contact.next()) {
  System.out.println(quot;<contact>...
Possible Perl code




print quot; <agenda>nquot;;
for $contact (@contacts) {
  print quot;<contact>nquot;;
  print quot; ...
Using XML::Writer::Simple




  print agenda(
     map { contact(
              name($_->{name}),
              email($_->...
What tags to use?




we want a function for each tag:
    easy for HTML!
and for XML?
    what are the valid tags?
    wh...
Full XML::Writer::Simple example




use XML::Writer::Simple
    tags => [qw/agenda contact name email tel/];

print agend...
Full XML::Writer::Simple example using a DTD




use XML::Writer::Simple
    dtd => quot;agenda.dtdquot;;

print agenda(
 ...
Full XML::Writer::Simple example using a sample file




use XML::Writer::Simple
    xml => [qw/mycontacts.xml morecontacts...
And about attributes?


  they do not need to be declared!
  just use them as you would under CGI.
  that is, use as first ...
And more! PowerTags



PowerTags:
    apply more than one XML tag;
    follow the Perl data structure;
PowerTag by example...
PowerTags — How to define them?




n levels;
Can be declared...
       use XML::Writer::Simple
           powertags=>[qw/u...
Five Minutes Yet?




Alberto Sim˜es ambs@cpan.org
           o                   XML::Writer::Simple
Upcoming SlideShare
Loading in...5
×

XML::Writer::Simple

2,485

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,485
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
26
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "XML::Writer::Simple"

  1. 1. XML::Writer::Simple Alberto Sim˜es o ambs@cpan.org Portuguese Perl Workshop 2008 Alberto Sim˜es ambs@cpan.org o XML::Writer::Simple
  2. 2. Why? XML wasn’t designed to be written manually; So, we normally generate XML; But then, we need to write it (in programs) And we do not want to do that! Alberto Sim˜es ambs@cpan.org o XML::Writer::Simple
  3. 3. Typical Java Code System.out.println(quot; <agenda>quot;); while(contact.next()) { System.out.println(quot;<contact>quot;); System.out.println(quot; <name>quot;+contact.name()+quot;</name>quot;); System.out.println(quot; <email>quot;+contact.mail()+quot;</email>quot;); System.out.println(quot; <tel>quot;+contact.tel()+quot;</tel>quot;); System.out.println(quot;</contact>quot;); } System.out.println(quot; </agenda>quot;); Alberto Sim˜es ambs@cpan.org o XML::Writer::Simple
  4. 4. Possible Perl code print quot; <agenda>nquot;; for $contact (@contacts) { print quot;<contact>nquot;; print quot; <name>$contact->{name}</name>nquot;; print quot; <email>$contact->{mail}</email>nquot;; print quot; <tel>$contact->{tel}</tel>nquot;; print quot;</contact>nquot;; } print quot; </agenda>nquot;; Alberto Sim˜es ambs@cpan.org o XML::Writer::Simple
  5. 5. Using XML::Writer::Simple print agenda( map { contact( name($_->{name}), email($_->{mail}), tel($_->{tel})) } @contacts ) Yeah, stolen from CGI! Alberto Sim˜es ambs@cpan.org o XML::Writer::Simple
  6. 6. What tags to use? we want a function for each tag: easy for HTML! and for XML? what are the valid tags? who tell us? Alberto Sim˜es ambs@cpan.org o XML::Writer::Simple
  7. 7. Full XML::Writer::Simple example use XML::Writer::Simple tags => [qw/agenda contact name email tel/]; print agenda( map { contact( name($_->{name}), email($_->{mail}), tel($_->{tel})) } @contacts ) Alberto Sim˜es ambs@cpan.org o XML::Writer::Simple
  8. 8. Full XML::Writer::Simple example using a DTD use XML::Writer::Simple dtd => quot;agenda.dtdquot;; print agenda( map { contact( name($_->{name}), email($_->{mail}), tel($_->{tel})) } @contacts ) Alberto Sim˜es ambs@cpan.org o XML::Writer::Simple
  9. 9. Full XML::Writer::Simple example using a sample file use XML::Writer::Simple xml => [qw/mycontacts.xml morecontacts.xml/]; print agenda( map { contact( name($_->{name}), email($_->{mail}), tel($_->{tel})) } @contacts ) Alberto Sim˜es ambs@cpan.org o XML::Writer::Simple
  10. 10. And about attributes? they do not need to be declared! just use them as you would under CGI. that is, use as first parameter an hash reference. use XML::Writer::Simple xml => [qw/mycontacts.xml morecontacts.xml/]; print agenda( map { contact( { owner => quot;ambs@di.uminho.ptquot; }, name($_->{name}), email($_->{mail}), tel($_->{tel})) } @contacts ) Alberto Sim˜es ambs@cpan.org o XML::Writer::Simple
  11. 11. And more! PowerTags PowerTags: apply more than one XML tag; follow the Perl data structure; PowerTag by example: ul_li(quot;aquot;,quot;bquot;,quot;cquot;) <ul><li>a</li><li>b</li><li>c</li></ul> ul_li({attr=>quot;valquot;},quot;aquot;,quot;bquot;) <ul attr=quot;valquot;><li>a</li><li>b</li></ul> or yet... table_tr_td( [quot;aquot;,quot;bquot;,quot;cquot;],[quot;dquot;,quot;equot;,quot;fquot;] ); Alberto Sim˜es ambs@cpan.org o XML::Writer::Simple
  12. 12. PowerTags — How to define them? n levels; Can be declared... use XML::Writer::Simple powertags=>[qw/ul_li ol_li/]; Can be created in runtime... powertag(quot;tablequot;,quot;trquot;,quot;tdquot;); Alberto Sim˜es ambs@cpan.org o XML::Writer::Simple
  13. 13. Five Minutes Yet? Alberto Sim˜es ambs@cpan.org o XML::Writer::Simple
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×