Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

lachoy (1663)

lachoy
  chris.winters@gmail.com
http://www.cwinters.com/

I am actually Chris Winters; I am actually living in Pittsburgh, Pennsylvania, USA; I am actually married and have three cats. (Guess what one of them is named?) I am the "OpenInteract" guy, which could be good or bad.

Journal of lachoy (1663)

Thursday February 10, 2005
11:28 AM

Useful but probably common XPath function

[ #23125 ]

I don't work with XML often enough to have this always at the ready, so: normalize-space() will take care of chomping sequences of whitespace to a single space. So when you're trying to match something like:

<p>This is my
Great Page Number Three
summary
</p

You can just use something like this and it will do the right thing (using dom4j if that matters):

String path = "//p[contains( normalize-space( text() ), 'This is my Great Page Number' )]";
List matching = doc.selectNodes( path );

(...and when I say 'XPath function' I actually mean 'XSLT function also used by XPath'. But since I'm just using XPath right now...)

Posted from cwinters.com; read original

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.