View ¡m../msn-2-html/MSN2HTML.pm¡n
# Name: # MSN2HTML.pm. # # Purpose: # Help process favorites.xml. See driver /scripts/general/msn-2-html.pl. # # Note: # tabs = 4 spaces || die. # # Keys in $$self: # Name Type Print # --------------------------------- # _current_favorite '' # _debug 0 0 => Nix, 1 => Some, 2 => Lots # _favorite_count 0 # _text '' # # Keys in $$self{$$self{_current_favorite} }: # Name Type Structure # ------------------------------------- # _title '' # _href '' # _created '' # # Programs in distribution: # MSN2HTML.pm # msn-2-html.pl # make-well-formed.pl # # Author: # Ron Savage
# http://savage.net.au/index.html # # Licence: # Australian Copyright (c) 1999-2002 Ron Savage. # # All Programs of mine are 'OSI Certified Open Source Software'; # you can redistribute them and/or modify them under the terms of # The Artistic License, a copy of which is available at: # http://www.opensource.org/licenses/index.html package MSN2HTML; use base qw/XML::SAX::Base/; # --------------------------------------------------------------------------------------- sub characters { my($self, $characters) = @_; $$self{_text} .= $$characters{Data}; } # End of characters. # --------------------------------------------------------------------------------------- sub end_document { my($self) = @_; if ($$self{_debug}) { print OUT "Favorite count: $$self{_favorite_count}. \n"; print OUT "\n"; print OUT "SAX Handler finishing. \n"; print OUT "\n"; } close(OUT); } # End of end_document. # --------------------------------------------------------------------------------------- sub end_element { my($self, $element) = @_; $$self{_text} =~ s/^\s+//; $$self{_text} =~ s/\s+$//; if ($$element{Name} eq 'title') { $$self{$$self{_current_favorite} }{_title} = $$self{_text}; if ($$self{_debug}) { print OUT "\ttitle: $$self{$$self{_current_favorite} }{_title}. \n"; print OUT "\n"; } } elsif ($$element{Name} eq 'href') { $$self{$$self{_current_favorite} }{_href} = $$self{_text}; if ($$self{_debug}) { print OUT "\thref: $$self{$$self{_current_favorite} }{_href}. \n"; print OUT "\n"; } } elsif ($$element{Name} eq 'created') { $$self{$$self{_current_favorite} }{_created} = $$self{_text}; if ($$self{_debug}) { print OUT "\tcreated: $$self{$$self{_current_favorite} }{_created}. \n"; print OUT "\n"; } } elsif ($$element{Name} eq 'favorite') { if ($$self{_inside_folder}) { push(@{$$self{_current_folder} }, [$$self{$$self{_current_favorite} }{_title}, $$self{$$self{_current_favorite} }{_href}, $$self{$$self{_current_favorite} }{_created}]); } else { push(@{$$self{_favorite} }, [$$self{_current_favorite}, $$self{$$self{_current_favorite} }{_lv}, $$self{$$self{_current_favorite} }{_vc}, $$self{$$self{_current_favorite} }{_title}, $$self{$$self{_current_favorite} }{_created}, $$self{$$self{_current_favorite} }{_href}]); } } elsif ($$element{Name} eq 'favfolder') { push(@{$$self{_folder} }, [$$self{_current_favfolder}, $$self{$$self{_current_favfolder} }{_title}, $$self{$$self{_current_favfolder} }{_created}, $$self{_current_folder}]); $$self{_inside_folder} = 0; $$self{_current_folder} = []; } elsif ($$element{Name} eq 'favorites') { } } # End of end_element. # --------------------------------------------------------------------------------------- sub new { my($type) = shift; my(%attr) = @_; my($self) = {}; @$self{keys %attr} = values %attr; $$self{_debug} = 0 if (! $$self{_debug}); $$self{_favorite} = []; $$self{_folder} = []; $$self{_inside_folder} = 0; if ($$self{_debug}) { open(OUT, '>> d:/temp/sax.log') || die("Can't open(> d:/temp/sax.log): $!"); } return bless $self, $type; } # End of new. # --------------------------------------------------------------------------------------- sub start_document { my($self) = @_; if ($$self{_debug}) { print OUT "SAX Handler starting. \n"; print OUT "\n"; } } # End of start_document. # --------------------------------------------------------------------------------------- sub start_element { my($self, $element) = @_; $$self{_text} = ''; if ($$element{Name} eq 'favorites') { } elsif ($$element{Name} eq 'favfolder') { $$self{_inside_folder} = 1; my($id) = $$element{Attributes}{'{}id'}{Value}; $$self{_current_favfolder} = $id; $$self{$id} = {}; $$self{$id}{_title} = $$element{Attributes}{'{}title'}{Value}; $$self{$id}{_created} = $$element{Attributes}{'{}created'}{Value}; $$self{_current_folder} = []; if ($$self{_debug}) { print OUT "Favfolder: $id. \n"; print OUT "\ttitle: $$self{$id}{_title}. \n"; print OUT "\tcreated: $$self{$id}{_created}. \n"; } } elsif ($$element{Name} eq 'favorite') { my($id) = $$element{Attributes}{'{}id'}{Value}; $$self{_current_favorite} = $id; $$self{$id} = {}; $$self{$id}{_lv} = $$element{Attributes}{'{}lv'}{Value}; $$self{$id}{_vc} = $$element{Attributes}{'{}vc'}{Value}; if ($$self{_debug}) { print OUT "Favorite: $id. \n"; print OUT "\tlv: $$self{$id}{_lv}. \n"; print OUT "\tvc: $$self{$id}{_vc}. \n"; } } elsif ($$element{Name} eq 'title') { } elsif ($$element{Name} eq 'href') { } elsif ($$element{Name} eq 'created') { } elsif ($$element{Name} eq 'propbag') { } else { die("Unexpected element: $$element{Name}. \n"); } } # End of start_element. # --------------------------------------------------------------------------------------- 1;