Your SlideShare is downloading. ×
XML::Liberal
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

XML::Liberal

3,023
views

Published on

in YAPC::NA 2006

in YAPC::NA 2006

Published in: Technology, News & Politics

1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total Views
3,023
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
76
Comments
1
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. XML::Liberal Tatsuhiko Miyagawa [email_address] Six Apart, Ltd. / Shibuya Perl Mongers YAPC::NA 2006 Chicago
  • 2.
    • Quiz:
    • What's wrong
    • with following XMLs?
  • 3. <?xml version=&quot;1.0&quot;?> <heroes>Larry & Damian</heroes>
  • 4. <?xml version=&quot;1.0&quot;?> <heroes>Larry &amp; Damian</heroes>
  • 5. <?xml version=&quot;1.0&quot;?> <shout> I &hearts; Perl &amp; Ruby! </shout>
  • 6. <?xml version=&quot;1.0&quot;?> <shout> I &#x2665; Perl &amp; Ruby! </shout>
  • 7. <?xml version=&quot;1.0&quot;?> <html> <body> <a href=foo.html>Foo foo!</a> </body> </html>
  • 8. <?xml version=&quot;1.0&quot;?> <html> <body> <a href= &quot;foo.html&quot; >Foo foo!</a> </body> </html>
  • 9. <?xml version=&quot;1.0&quot;?> <html> <body> <a href=&quot;/search?q=YAPC+NA&hl=en&quot;>Search for YAPC</a> </body> </html>
  • 10. <?xml version=&quot;1.0&quot;?> <html> <body> <a href=&quot;/search?q=YAPC+NA &amp; hl=en&quot;>Search for YAPC</a> </body> </html>
  • 11. <?xml version=&quot;1.0&quot;?> <rss version=&quot;2.0&quot;> <channel> <item> <title>YAPC is love</title> <content:encoded>Here I am!</content:encoded> </item> </channel> </rss>
  • 12. <?xml version=&quot;1.0&quot;?> <rss version=&quot;2.0 xmlns:content=&quot;http://purl.org/rss/1.0/modules/content/&quot; > <channel> <item> <title>YAPC is love</title> <content:encoded>Here I am!</content:encoded> </item> </channel> </rss>
  • 13. <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?> <search> <result> <excerpt>YAPC 最高 ! ...</excerpt> </result> </search>
  • 14. <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?> <search> <result> <excerpt>YAPC 最高 ! □ ...</excerpt> </result> </search>
  • 15.
    • If you're
    • a feed publisher,
    • Make sure
    • your feed is valid.
  • 16.
    • If you're a feed consumer,
    • Not being able
    • to parse broken feeds
    • might make your users unhappy.
  • 17.
    • As we saw
    • in the Quiz
  • 18.
    • Detecting XML errors
    • Is easy and simple
    • (sometimes).
  • 19.
    • Browsers deal
    • With it.
  • 20.
    • Human can
    • parse it.
  • 21.
    • Why not XML parsers
    • doing the same thing?
  • 22.
    • XML::Liberal
    • Does it for you.
  • 23.
    • Demo
  • 24.
    • Usage #1
    • If you use XML::LibXML
  • 25. use strict; use XML::LibXML; my $parser = XML::LibXML->new; my $doc = $parser->parse_string($xml);
  • 26. use strict; use XML::Liberal; my $parser = XML::Liberal->new(&quot;LibXML&quot;); my $doc = $parser->parse_string($xml);
  • 27.
    • Note: There's NO
    • performance drawback
    • If the data is valid
  • 28.
    • $parser->max_fallback(3)
  • 29.
    • Usage #2
    • If you use XML::LibXML
    • Without control to
    • change the code
  • 30. use strict; use XML::Liberal; XML::Liberal->globally_override('LibXML'); # later on … my $parser = XML::LibXML->new;
  • 31.
    • Usage #3
    • If you don't use LibXML
  • 32. use strict; use XML::FooParser; $doc = parse_xml($xml);
  • 33. use strict; use XML::FooParser; use XML::Liberal; eval { $doc = parse_xml($xml) }; if ($@){ my $p = XML::Liberal->new('LibXML'); my $d = $p->parse_string($xml); $xml = $d->toString(1); $doc = parse_xml($xml); }
  • 34.
    • XML::Liberal
    • Came out of Plagger
    • http://plagger.org/
  • 35.
    • cpan XML::Liberal
  • 36.
    • Thank you