On Wed, May 06, 2009 at 10:48:12PM -0400, Josh Suereth wrote:
> Here's similar java (but using a different path)...
>
> List<String> urls = new ArrayList<String>();
> NodeList links = webpageDom.getElementsByTagName("a");
> for(int i =0; i < links.getLength(); i++) {
> Node link = links.item(i);
> if(link instanceof Element) {
> Element linkAsElement = (Element)link;
> if(linkAsElement.hasAttribute("href") &&
> linkAsElement.getAttribute("href").endsWith("rpm")) {
> urls.add(linkAsElement.getAttribute("href");
> }
> }
> }
I'm not totally sure about XPath APIs in Java, but XPath is just the ticket
for this sort of thing. Something like:
//a[ends-with(@href, 'rpm')]
Much like I don't do complicated text processing without regexes (or
perhaps a parser), I wouldn't do complicated DOM stuff without at least
considering XPath.
-Dom
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---