How do I visualise/pretty-print a HTML DOM tree? - perl

Now that I can navigate a Web page via WWW::Mechanize and get information via HTML::TreeBuilder::XPath by accessing an id, I am left using Firebug to read the DOM in order to discover the layout of the HTML tree. The content that Mechanize captures is unstructured HTML, not good for human eyes.
Is using Firebug to ascertain the id I am after a typical approach? Once I get the id then I'm good to go, it's just that I've got several ids and pages with more ids to chase down and I was hoping to get (dump, print, etc.) a formatted layout of the DOM in order to make that discovery easier. Though granted, Firebug makes it pretty easy, too. I'm just wondering if I am missing an easier method.
Crossposted at PerlMonks.

If you need text, xmllint --html --format (comes with libxml2) does a decent job.
If you want a tree and mess with it and test out various expressions in a GUI, then Xacobeo is your new best friend.
Note: since both those tools rely on libxml, replace HTML::TreeBuilder::XPath with HTML::TreeBuilder::LibXML for compatibility. Evaluating XPath will be faster that way, too.
If you know Javascript/JQuery, then also install FireQuery. You can then test out CSS expressions in FireBug, and use them with modules that select HTML through CSS expressions, e.g. Web::Query.

I use XML Developer from Oxygen IDE for my recent development on XPath:
http://www.oxygenxml.com/download.html
It is a 30-day trial type of tool, but you can also search for XPath visualizer
It doesn't visualize a tree for you as far as I know (maybe there's a panel doing that). But it gives you some smart complete functionally that helps you to know what nodes you have available at any point. It is pretty big for XPath because it is hard to know where the parser pivot is really pointing at.

Related

Script to fill browser form

I have little business problem, I need to make a script to fill (not send) out browser forms(only simple textfields, checkboxes and drop downboxes).
I need to launch multiple windows with the same form with different data to speed up form filling
What kind of scripting/programming do I need to use to fulfill these needs(Batch, JS .. ) ?
I have knowledge only of java, and basic html,c,c++ ... so if I can get basic tutorials I would be grateful indeed.
I have bits of ideas of how this is possible - through IDs of various field on the page which I can access to edit their values, so I just need language specific tutorials/suggestions.
Batch would be preferable if possible, because i need to execute the script through a java swing program.
P.S : If this is of any relevance, only browser acceptable is IE
dont think its possible through Batch,
I think easiest would be javaScript for this task. (chill js is pretty easy)
You can write a simple javaScript to fill in form
You should find how to fill form through javaScript helpful
Then you can use ScriptEngineManager to execute javaScript from your java code.
This tutorial should be helpful :execute javascript from java
You can't fill HTML-fields with a Batch-File. The easiest way is to use Javascript an Greasemonkey in Mozilla Firefox. You can find Tutorials here.
An other way to send data to an WebServer is to use in C/C++/Java Sockets and the HTML-Protocol.

How to define custom wicket tag

I could not find a wicket tag like wicket:include? Can anyone suggest me anything? I want to include/inject raw source into html files? If there is no such utility, any suggestions to develop it?
update
i am looking for sth like jsp:include. this inclusion is expected to be handled on the server side.
To do this, you'll need to implement your own IComponentResolver.
This blog article shows an example somewhat resembling what you're after.
Is it raw markup that you want to include, or Wicket content?
If it's raw markup, even a simple Label can do that for you. If you call setEscapeModelStrings( false), the string value of the model will be copied straight in the markup. (Watch out for potential XSS attacks though.)
"Including" Wicket markup is done via Panels (or occasionally Fragments)
Update: If you add more detail about the actual problem you need to solve, there's a good chance that we can find a more "wickety" solution, after all, JSP and Wicket are two different worlds and the mindset of one doesn't work very well in the other.

separate layout from templates in perl cgi::application

I am building a perl cgi::application using html::template.
I am using 7-8 different templates having the same layout - header, footer, left column etc.
How can I separate this html out of the template files into a single layout file. What perl modules do I need in addition to cgi::app and html::template.
Thanks
I agee that Template-Tookit is better.
If you absolutely have to use HTML::Template you can use the TMPL_INCLUDE directive. It'll search your defined template paths or you can specify a full path to another template. It'll process the variables in it as well.
You can create seperate template files for the header, footer and such and in your page templates just TMPL_INCLUDE them. It's less elegant and more repetative than Template Toolkit's WRAPPER (You'll have to TMPL_INCLUDE in each page several times for all shared elements) but it'll get the job done.
If you can, invest the time and use Template Toolkit.
I'd switch out HTML::Template for Template-Toolkit and make use of it's WRAPPER directive.
I don't know about Template-Toolkit. So i won't discuss about which solution is the most convenient.
I can just give you another solution, which is dependant of the server your running your cgi's on.
With Apache server, you can use includes in your html :
<!--#include virtual="/includes/header/header.htm"-->
you may call htm (static pages) as well as dynamic pages :
<!--#include virtual="/perl/includes/dynamic.pl"-->
but you have to do some apache tweaking. see Apache Tutorial: Introduction to Server Side Includes
Hope this will help, or at least give some ideas
Can the people who don't like HTML::Template please say why? While the Wrapper idea seems helpful to this particular poster, there's nothing wrong with the idea of includes: they're more flexible, and many web developers will already be familiar with the concept from non-dynamic publishing.

Suggestions for a very easy to edit CMS?

I need advice/suggestions.
At my place of work - we have a large data set.
We would like to server the data up as editable html pages.
(Its mostly lists of simple text)
We would like to add data, change it's order, update text etc...from the editable pages.
It has to have a pretty low bar for usability and WYSIWYG is a must.
The folks who will edit are not programmers by a long shot.
We are not sure Wiki will work.
It might have to do - but not sure.
Changes have to be tracked and written back into the DB
I am thinking some kind of open source CMS might work?
Wordpress, Joomla, Drupal - something that can get us up and running pretty quickly.
I really am open to suggestions - not sure where to begin on this one.
Thanks all
If you don't have someone available right now with expertise with a specific CMS, it will not be quick to set up at all. One good reason is that you'd have to import all of your existing data into whatever form the CMS supports: this is a task for someone who has done it before. On the other hand, if you can pull that off, some of the built in WYSIWYG editors are quite easy to use, with some systems you get versioning and author information for free etc. I'm speaking mostly with the eZ Publish CMS in mind, although it's probably true for other systems.
I would make a simple CMS site that uses the Ajax control toolkit HTML Editor and perform updates to the database on postback.
Here is the link to the Editor example
http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/HTMLEditor/HTMLEditor.aspx
CMS Made Simple (http://www.cmsmadesimple.org) is very easy to set up and use. You do need to understand xhtml and javascript for the theme whacking, but once it's set up it has been trouble free. See my http://www.ConvinceProject.com as an example. It is MUCH easier to use than Drupal and appears to be more stable. I've had Drupal crash when installing security updates to modules, for example. It gives you full access to the header metatags, has fully integrated php and smarty tags, seems quite complete.
AFA importing, this is all mysql-based, although it can use others. If you have a web-whacking coder, pages can be 'scraped' and stuffed if it's more than cut and paste will do.
Lots of us can do it, it's not hard.
If I understand you correctly, it seems like you just need a web-based GUI for editing your DB. Honestly it would probably be faster to just roll your own in the language most familiar to you. There are many fine WYSIWYG editors out there that you can wrap around a text field, such as http://ckeditor.com/.
On the the other hand if you're hoping to solve this problem with DB skills and not do any web dev it may indeed be easier to find a simple CMS. ModX and SimpleCMS comes to mind. Joomla, Drupal and WP all come with so many out of the box features you'd have to strip out - look for something that starts fairly simple. Drupal in the right hands could do this, it has tools for importing/exporting to external DBs but the learning curve is pretty steep. Be aware that some CMSes do strange things with entry data...you may have to look for a text field inside a stored array (Drupal) instead of stored as a straight text field.

Developing a GUI Builder Application

I am looking for a nice framework for developing a GUI builder Application. We have an application where 100Os of custom data entry forms and their print formats are required and each client will need some modifications on these. We have a developed a product using java based open source templatnig frameworks so that the layout and field definition are stored in database and rendered dynamically to the user. We also have an appication to design these forms but cannot do visual design.
Now I am trying to make a Visual Form Designer application for generating these forms. Can any one suggest some open source frameworks than can be used? Can I use Eclipse Visual Editor? Or is it better to develop some kind of parser for HTML using AntLR and then parse the HTML output from already existing GUI builders like Dreamweaver to get the desired output?
Thanks and Regards,
-- Kannan
Oooh, great question!
I wouldn't know any readily availble framework that you can use. Depending on your needs however, I think rolling your own shouldn't be too hard.
First of all, you probably wouldn't want to give the users too much freedom. Freedom only gives them the opportunity to mess things up and make the resultant forms hard to use. I think from your description that the fields are pre-defined, so that the user only needs to customize which fields appear on a given form, and in what order. Order can be a simple thing like top-to-bottom. Some semi-intelligent automatic layouting could be used to conserve screen space. Adding a feature to group fields together would probably also be useful, and grouping would lead to some kind of standard "group" widget.
Accepting simplified functionality like this, you don't really need the flexibility of a full gui editor. A couple of listviews, maybe a property sheet and a preview window will be enough to give your users the functionality they need.
Of course, this only holds for screen forms. Print forms may be trickier to layout, as people may want to cram as many fields as possible into very little space so the entire form can fit on a single page or something. I really don't have any suggestions for you there, but maybe a similar "simplified" approach with some intelligent auto-layouting could work.
Overall, my advice would be: Keep It Simple! (S... ;)