Ben, A couple of things to get started: 1. This document isn't well formed xml. Try to check the well formedness in your editor and you'll get a message about not being able to define a default namespace in the DTD. You need <html xmlns="http://www.w3.org/1999/xhmtl"> to replace your html element to define a default namespace for the rest of the document (and/or check out this link http://www.biglist.com/lists/xsl-list/archives/200104/msg00568.html Jeni describes other ways to define the namespace using the DTD - I don't do this much so I would just confuse the issue more) 2. the reason you aren't getting anything back is due to the lack of a namespace or default namespace 3. After doing (1) use your xpath tool and set a namespace with a prefix (or set a default if you can) I used xmlns:xhtml="http:www.w3.org/1999/xhtml"
Then to your original example do //xhtml:[EMAIL PROTECTED] and you'll get a node list of the elements. I'm not sure how to do this in dom4j (I'm just learning the api's myself) but you should be able to set a namespace and prefix. If this doesn't fix your problem I hope it sheds some light on what's actually happening. I've got a busy day today, but I'll try to look at this later if I get a chance. Hope this helps! Marty -----Original Message----- From: Ben Munat [mailto:[EMAIL PROTECTED] Sent: Thursday, January 15, 2004 1:57 AM To: [EMAIL PROTECTED] Subject: Re: [dom4j-user] xpath not working McDonough, Michael wrote: > While a valid html file, do you know whether it is a well-formed XML > document? Bradley, Martin wrote: > do you have a way to externally test the xpath expression into your html > doc? I use Xselerator. If you don't post the sample html and I can > verify the path is returning a nodelist. Thanks for getting back to me... good idea. I used a prog called XmEdil which has an xpath tester (and tests the doc for validty and well-formednes when I open it). And, it seems I am doing something wrong with the xpath: when I select "/" I get the whole doc still, but when I put in any other xpath (//head, //p, etc.) I get no results. Now, when I select "/", the xpath tester lists its result as being of type "document"... does this mean that I have to "get into" the document before my xpaths will work? I don't remember any such thing from my xpath/xsl class. And actually, I already tried running the dom4j xpath methods after selecting the root node of the document: Element root = d.getRootElement(); Node n = root.selectSingleNode("//p"); That doesn't work either. :-( Anyway, here's the html... hope you guys have more ideas. Thanks, Ben PS: Just noticed that the xpath builder window has a tab called "nodes" which shows a list of the elements and attributes in my doc (p, div, a, class, etc). So, it's even figuring out that there are sub nodes within this "document" element... but I can't select them with xpaths!? ------------------------------------------------- Using this as test doc: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title> test page </title> </head> <body> <div class="navbox"> <p> SITE LINKS: </p> <a href="#">A link</a><br /> <a href="#">A link again</a><br /> <a href="#">Another link</a><br /> <a href="#">A link too</a><br /> </div> <div class="content"> <h1> Test page! </h1> <p> Lobore et dolore nagna aliquam erat volupat. At enim ad minimin veniami quis nostrud exercitation lorem ipsum dolor sit amet, consectetur adips cing elit, diam nonnumy eiusmod tempor incidunt ut ullamcorper suscripit laboris nisi ut alquip exea commodo consequat, consectetur adips cing elit. </p> </div> </body> </html> ------------------------------------------------------- This SF.net email is sponsored by: Perforce Software. Perforce is the Fast Software Configuration Management System offering advanced branching capabilities and atomic changes on 50+ platforms. Free Eval! http://www.perforce.com/perforce/loadprog.html _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user NOTICE: This E-mail may contain confidential information. If you are not the addressee or the intended recipient please do not read this E-mail and please immediately delete this e-mail message and any attachments from your workstation or network mail system. If you are the addressee or the intended recipient and you save or print a copy of this E-mail, please place it in an appropriate file, depending on whether confidential information is contained in the message. ------------------------------------------------------- This SF.net email is sponsored by: Perforce Software. Perforce is the Fast Software Configuration Management System offering advanced branching capabilities and atomic changes on 50+ platforms. Free Eval! http://www.perforce.com/perforce/loadprog.html _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user