XML::Liberal Tatsuhiko Miyagawa   [email_address] Six Apart, Ltd. / Shibuya Perl Mongers YAPC::NA 2006 Chicago
<ul><li>Quiz: </li></ul><ul><li>What's wrong </li></ul><ul><li>with following XMLs? </li></ul>
<?xml version=&quot;1.0&quot;?> <heroes>Larry & Damian</heroes>
<?xml version=&quot;1.0&quot;?> <heroes>Larry  &amp;  Damian</heroes>
<?xml version=&quot;1.0&quot;?> <shout> I &hearts; Perl &amp; Ruby! </shout>
<?xml version=&quot;1.0&quot;?> <shout> I  ♥  Perl &amp; Ruby! </shout>
<?xml version=&quot;1.0&quot;?> <html> <body> <a href=foo.html>Foo foo!</a> </body> </html>
<?xml version=&quot;1.0&quot;?> <html> <body> <a href= &quot;foo.html&quot; >Foo foo!</a> </body> </html>
<?xml version=&quot;1.0&quot;?> <html> <body> <a href=&quot;/search?q=YAPC+NA&hl=en&quot;>Search for YAPC</a> </body> </ht...
<?xml version=&quot;1.0&quot;?> <html> <body> <a href=&quot;/search?q=YAPC+NA &amp; hl=en&quot;>Search for YAPC</a> </body...
<?xml version=&quot;1.0&quot;?> <rss version=&quot;2.0&quot;> <channel> <item> <title>YAPC is love</title> <content:encode...
<?xml version=&quot;1.0&quot;?> <rss version=&quot;2.0 xmlns:content=&quot;http://purl.org/rss/1.0/modules/content/&quot; ...
<?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?> <search> <result> <excerpt>YAPC  最高 ! ...</excerpt> </result> <...
<?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?> <search> <result> <excerpt>YAPC  最高 ! □ ...</excerpt> </result>...
<ul><li>If you're </li></ul><ul><li>a feed publisher, </li></ul><ul><li>Make sure </li></ul><ul><li>your feed is valid. </...
<ul><li>If you're a feed consumer, </li></ul><ul><li>Not being able </li></ul><ul><li>to parse broken feeds  </li></ul><ul...
<ul><li>As we saw </li></ul><ul><li>in the Quiz </li></ul>
<ul><li>Detecting XML errors </li></ul><ul><li>Is easy and simple </li></ul><ul><li>(sometimes). </li></ul>
<ul><li>Browsers deal </li></ul><ul><li>With it. </li></ul>
<ul><li>Human can </li></ul><ul><li>parse it. </li></ul>
<ul><li>Why not XML parsers </li></ul><ul><li>doing the same thing? </li></ul>
<ul><li>XML::Liberal </li></ul><ul><li>Does it for you. </li></ul>
<ul><li>Demo </li></ul>
<ul><li>Usage #1 </li></ul><ul><li>If you use XML::LibXML </li></ul>
use strict; use XML::LibXML; my $parser = XML::LibXML->new; my $doc = $parser->parse_string($xml);
use strict; use XML::Liberal; my $parser =  XML::Liberal->new(&quot;LibXML&quot;); my $doc = $parser->parse_string($xml);
<ul><li>Note: There's NO </li></ul><ul><li>performance drawback </li></ul><ul><li>If the data is valid </li></ul>
<ul><li>$parser->max_fallback(3) </li></ul>
<ul><li>Usage #2 </li></ul><ul><li>If you use XML::LibXML </li></ul><ul><li>Without control to </li></ul><ul><li>change th...
use strict; use XML::Liberal; XML::Liberal->globally_override('LibXML'); # later on … my $parser = XML::LibXML->new;
<ul><li>Usage #3 </li></ul><ul><li>If you don't use LibXML </li></ul>
use strict; use XML::FooParser; $doc = parse_xml($xml);
use strict; use XML::FooParser; use XML::Liberal; eval { $doc = parse_xml($xml) }; if ($@){ my $p = XML::Liberal->new('Lib...
<ul><li>XML::Liberal </li></ul><ul><li>Came out of Plagger </li></ul><ul><li>http://plagger.org/ </li></ul>
<ul><li>cpan XML::Liberal </li></ul>
<ul><li>Thank you </li></ul>
Upcoming SlideShare
Loading in...5
×

XML::Liberal

3,149

Published on

in YAPC::NA 2006

Published in: Technology, News & Politics
1 Comment
3 Likes
Statistics
Notes
No Downloads
Views
Total Views
3,149
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
76
Comments
1
Likes
3
Embeds 0
No embeds

No notes for slide

XML::Liberal

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

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

×