Posts

Showing posts from August, 2008

Setting the onSubmit handler with JavaScript

A common issue -- setting the onSubmit event handler of a form with JavaScript. I mean, it's easy enough to set it with <form id='theForm' onsubmit="return confirm('Really submit?');"> but here is how to do it with JavaScript <script type='text/javascript'> document.getElementyById('theForm').onSubmit = function() { return confirm('Really submit?'); }; </script>

Parsing HTML with Perl and XPath

I have had to write an HTML parser a few times already and I've always used HTML::Parser . Because it's simple and because I never bothered to do it anohter way. I always wanted to ideally do some parsing with XPath because that way I can easily find what I need with one or two queries. Unfortunately, XPath only works on properly formatted XML documents, so unless the page I am parsing is XHTML, I couldn't do much. I also wanted to somehow convert the HTML to properly formatted XHTML and use XPath with that. Unfortunately, I didn't know an easy way to do that either. Well, now I do. I can use the HTML::TreeBuilder module from HTML-Tree CPAN distribution. It is easy enough to use the module itself for parsing: my $tree = HTML::TreeBuilder->new_from_file("test.html"); my @img = $tree->look_down('tag', 'img', sub { $_[0]->attribute("src") =~ m!thumbnail!; } However, as I would rather use XPath, here is how to easily convert t

VS 2005 does not want to profile my ASP.NET project

Image
Visual Studio 2005 does not want to profile my ASP.NET project! What's up with that? This is with the Team Edition that has the quite useful "Performance Tools" included. However, when I start a new Performance Wizard I don't see my ASP.NET web site project in the list of profileable projects. To make a long story short, the solution is to not select the "No Start Page" option in the debug dialog as shown in the following figure. Checking "Current Page" does not work either. Just to be safe, go with "Specific Page" and pick something from the list.