Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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
You’ve finished this document.
Download and read it offline.
Upcoming SlideShare
El próximo escenario global
Next
Upcoming SlideShare
El próximo escenario global
Next
Download to read offline and view in fullscreen.

Share

XML::Writer::Simple

Download to read offline

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

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

Views

Total views

3,344

On Slideshare

0

From embeds

0

Number of embeds

15

Actions

Downloads

27

Shares

0

Comments

0

Likes

0

×