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

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

XML::Liberal

3,104

Published on

in YAPC::NA 2006

in YAPC::NA 2006

Published in: Technology, News & Politics
1 Comment
3 Likes
Statistics
Notes
No Downloads
Views
Total Views
3,104
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
76
Comments
1
Likes
3
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. <ul><li>Quiz: </li></ul><ul><li>What's wrong </li></ul><ul><li>with following XMLs? </li></ul>
  • 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 ♥ 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. <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. <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. <ul><li>As we saw </li></ul><ul><li>in the Quiz </li></ul>
  • 18. <ul><li>Detecting XML errors </li></ul><ul><li>Is easy and simple </li></ul><ul><li>(sometimes). </li></ul>
  • 19. <ul><li>Browsers deal </li></ul><ul><li>With it. </li></ul>
  • 20. <ul><li>Human can </li></ul><ul><li>parse it. </li></ul>
  • 21. <ul><li>Why not XML parsers </li></ul><ul><li>doing the same thing? </li></ul>
  • 22. <ul><li>XML::Liberal </li></ul><ul><li>Does it for you. </li></ul>
  • 23. <ul><li>Demo </li></ul>
  • 24. <ul><li>Usage #1 </li></ul><ul><li>If you use XML::LibXML </li></ul>
  • 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. <ul><li>Note: There's NO </li></ul><ul><li>performance drawback </li></ul><ul><li>If the data is valid </li></ul>
  • 28. <ul><li>$parser->max_fallback(3) </li></ul>
  • 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. use strict; use XML::Liberal; XML::Liberal->globally_override('LibXML'); # later on … my $parser = XML::LibXML->new;
  • 31. <ul><li>Usage #3 </li></ul><ul><li>If you don't use LibXML </li></ul>
  • 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. <ul><li>XML::Liberal </li></ul><ul><li>Came out of Plagger </li></ul><ul><li>http://plagger.org/ </li></ul>
  • 35. <ul><li>cpan XML::Liberal </li></ul>
  • 36. <ul><li>Thank you </li></ul>

×