diff --git a/lib/DDG/Goodie/IsValid/XML.pm b/lib/DDG/Goodie/IsValid/XML.pm new file mode 100644 index 000000000..6e778e41d --- /dev/null +++ b/lib/DDG/Goodie/IsValid/XML.pm @@ -0,0 +1,24 @@ +package DDG::Goodie::IsValid::XML; + +use DDG::Goodie; + +use Try::Tiny; +use XML::Simple; + +zci answer_type => 'isvalid'; +zci is_cached => 1; + +triggers start => 'is valid xml', 'validate xml'; + +handle remainder => sub { + my $result = try { + XMLin($_); + return 'valid'; + } catch { + return 'invalid'; + }; + + return "Your XML is $result!"; +}; + +1; diff --git a/t/IsValid.t b/t/IsValid.t index db4ca5a5e..d4da2e2dc 100755 --- a/t/IsValid.t +++ b/t/IsValid.t @@ -19,4 +19,14 @@ ddg_goodie_test( 'is valid json {"test" "lol"}' => test_zci('Your JSON is invalid!'), ); +ddg_goodie_test( + [qw(DDG::Goodie::IsValid::XML)], + 'is valid xml ' => test_zci('Your XML is valid!'), +); + +ddg_goodie_test( + [qw(DDG::Goodie::IsValid::XML)], + 'is valid xml lol' => test_zci('Your XML is invalid!'), +); + done_testing;