XML::Liberal
Upcoming SlideShare
Loading in...5
×
 

XML::Liberal

on

  • 5,080 views

in YAPC::NA 2006

in YAPC::NA 2006

Statistics

Views

Total Views
5,080
Views on SlideShare
5,077
Embed Views
3

Actions

Likes
2
Downloads
74
Comments
1

1 Embed 3

http://www.slideshare.net 3

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Outstanding demonstration. Really clear along with useful

    Janie
    http://financejedi.com
    http://healthjedi.com
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

XML::Liberal XML::Liberal Presentation Transcript

  • XML::Liberal Tatsuhiko Miyagawa [email_address] Six Apart, Ltd. / Shibuya Perl Mongers YAPC::NA 2006 Chicago
    • Quiz:
    • What's wrong
    • with following XMLs?
  • <?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 &#x2665; 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> </html>
  • <?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>
  • <?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>
  • <?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>
  • <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?> <search> <result> <excerpt>YAPC 最高 ! ...</excerpt> </result> </search>
  • <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?> <search> <result> <excerpt>YAPC 最高 ! □ ...</excerpt> </result> </search>
    • If you're
    • a feed publisher,
    • Make sure
    • your feed is valid.
    • If you're a feed consumer,
    • Not being able
    • to parse broken feeds
    • might make your users unhappy.
    • As we saw
    • in the Quiz
    • Detecting XML errors
    • Is easy and simple
    • (sometimes).
    • Browsers deal
    • With it.
    • Human can
    • parse it.
    • Why not XML parsers
    • doing the same thing?
    • XML::Liberal
    • Does it for you.
    • Demo
    • Usage #1
    • If you use XML::LibXML
  • 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);
    • Note: There's NO
    • performance drawback
    • If the data is valid
    • $parser->max_fallback(3)
    • Usage #2
    • If you use XML::LibXML
    • Without control to
    • change the code
  • use strict; use XML::Liberal; XML::Liberal->globally_override('LibXML'); # later on … my $parser = XML::LibXML->new;
    • Usage #3
    • If you don't use LibXML
  • 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('LibXML'); my $d = $p->parse_string($xml); $xml = $d->toString(1); $doc = parse_xml($xml); }
    • XML::Liberal
    • Came out of Plagger
    • http://plagger.org/
    • cpan XML::Liberal
    • Thank you