XML, the Perl Way

Home XML::Twig Modules Talks Articles Tutorials Reports Tools PGC mirod Le Blog

03 Mar 2006

Module News: New *XPath* modules

I recently released 4 XPath-related modules on CPAN, so here is a little introduction:

There are 2 basic modules: XML::XPathEngine and Tree::XPathEngine. These 2 modules are basically a repackaging of XML:XPath. The 2 other modules, HTML::TreeBuilder::XPath and Tree::DAG_Node::XPath use those modules to add XPath support to respectively /HTML::TreeBuilder and Tree::DAG_Node.

XML::XPathEngine is very close to XML::XPath. I changed node sets so they can sort any node type that offers a cmp method), applied a few bug fixes (the ones I have had on RT for nearly 2 years now. I also integrated regular expressions into the language (see the docs). XML::XPathEngine should be used to add XPath support to XML or HTML modules. It creates objects that evaluate XPath expressions on a DOM. So as long as the calling module can fake a DOM convincingly enough, XML::XPathEngine will evaluate XPath expressions. The closer the calling module mimicks a DOM, the more of XPath is supported.

HTML::TreeBuilder::XPath uses XML::XPathEngine, and adds methods like findnodes and findvalue to any tree (in fact to any HTML::Element object).

Tree::XPathEngine is a simplified version of XML::XPathEngine, for "non-.*ML" trees. They assume a simpler model (tree, nodes, attributes, optional text value for nodes) and the names of methods are more perlish (no camelCase). It also allows a different regexp to be used for node and attribute names, so you're not limited to XML names.

Tree::DAG_Node::XPath adds the usual findnodes, findvalue... to Tree::DAG_Node.

The idea for these modules stemmed from my XXX (eXtending XML::XPath) article and talk. I felt that it was worth re-using XML::XPath, and making it easier to re-use. Plus the module did not seem to be really maintained, so I wanted to be able to at least fix the bugs.

The docs for the *::XPathEngine modules are probably a little lacking at this point, and I would welcome any feedback on them, especially from people who would use the modules to add XPath to other modules (WWW::Mechanize anyone?).

[Module News] [permalink]



Comments

Recent

Archives

2006