Hi David Sorry for the slow response; I've been a little swamped lately.
FWIW in your original example, the following XPath will work fine... /*/oi:thing-info/@triggering-document-expression I've added your test case to dom4j/xml/test/DavidHooker.xml and added some valid XPath expressions to the XPath tester at dom4j/xml/test/xpath/tests.xml. Generally the reason for your problem is that default namespaces don't work nicely in XPath. If you had a document like this <doc xmlns="foo">hello</doc> Then the XPath expression /doc will not match anything! This might seem kinda strange at first but its because the name comparison uses namespace URIs. Incidentally if you change your document to use a prefix... <d:doc xmlns="foo">hello</d:doc> Then you can use the XPath expression /d:doc in dom4j. If you don't specify a NamespaceContext, dom4j will use the default namespaces in scope on the node on which you perform the query, which for a document will be the root element. For example I modified your example slightly to use the element... <atomic:thing xmlns:atomic="http://www.a4networks.com/schemas/atomic-thing" And then the following XPath expressions all work fine... /atomic:thing/oi:thing-info/@triggering-document-expression //@triggering-document-expression James ----- Original Message ----- From: "David Hooker" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, November 06, 2001 8:51 PM Subject: [dom4j-user] Help with XPath expression > Hi all- > > I'm using dom4j to build a document, and I'm trying to select a node > using an XPath expression. Can someone tell me why the line: > > Node nameNode = > document.selectSingleNode("//@triggering-document-expression"); > > works when the line > > Node nameNode = > document.selectSingleNode("/atomic-thing/oi:thing-info/@triggering-docum > ent-expression"); > > does not. > > Here's the xml: > > <?xml version="1.0" encoding="UTF-8"?> > <atomic-thing xmlns="http://www.a4networks.com/schemas/atomic-thing" > xmlns:oi="http://www.a4networks.com/schemas/thing-info" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > > xsi:schemaLocation="http://www.a4networks.com/schemas/atomic-opl > C:/work/atomic-thing.xsd" > > > <oi:thing-info owner="dhooker" > author="dhooker" > thing-version="1" > date-modified="2001-11-05" > triggering-document-expression="/a/b/c/d" > thing-type="transform" > check-for-duplicate="yes" > sharing="private"/> > </atomic-thing> > > > > > _______________________________________________ > dom4j-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/dom4j-user > _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user
