Hi,

I remember having a problem with this when I started using dom4j and unfortunately, I can't remember exactly how I got around it. (I would probably not even reply and let someone more knowledgeable help you, but this is a rather quiet list... or, more accurately, a rather one-sided list.)

It seems to me that the trouble had something to do with the document having a doctype declaration. I don't know why that would screw up an xpath, but it seems like I had more luck when I took the dtd declaration out. I know that pretty much sucks, but...

Yeah, I just went and tried it and this works when there's no dtd, but finds nothing when there is:

        Document temp = reader.read(new File("c:/testindex.html"));
        Node title = temp.selectSingleNode("//title");
        System.out.println(">>>"+title.asXML());

I don't think I ever got an answer as to why that is so. Well, if you can't get rid of the dtd, try playing around with more explicit xpaths and from deeper contexts... seems like that worked for me too.

Good luck to ya!

Ben

PS: please let me know if you figure out what the trick is... I'll have to write it down this time.



D'Arcy Norman wrote:
I'm having some odd difficulties using dom4j to process XPath statements on my documents. I've been working through the quick start, and have browsed the mailing list, so I hope I'm not overlooking something, or doing something really dumb...

I retrieve my XML from an XML database (XStreamDB), and successfully feed it to dom4j to get back an Element (or a Document) representing the contents of the xml document.

Now, I'm trying to use dom4j to process the contents of the Document to pull out some values (and to insert/change some values).

I'm doing something like this (I've simplified the XPath to show something that should have at least one value in my document):


String xmlContent = (some magical process to get it from the database)
Document myDocument = reader.read( new InputSource( new StringReader( xmlContent ) ) ).getDocument();
XPath xpath = DocumentHelper.createXPath( "//identifier" );
Node identifierNode = xpath.selectSingleNode( myDocument );
List matchingNodes = xpath.selectNodes( myDocument );
System.out.println( identifierNode );
System.out.println( matchingNodes );


All I get for identifierNode is null, and matchingNodes is an empty List.

My documents have at least one "identifier" element, so I'm confused why dom4j isn't finding either.

If I open up the xpath selector to be something like "//string" (there are dozens of "string" elements in each document), I still get null for the selectSingleNode(), and an empty List for selectNodes().

Any ideas, tips or hints would be greatly appreciated!


- D'Arcy Norman Software Developer Learning Commons, The University of Calgary [EMAIL PROTECTED] http://careo.ucalgary.ca http://commons.ucalgary.ca/weblogs/dnorman (403) 220-2504 AIM/iChatAV: [EMAIL PROTECTED]



-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user



-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to