On Thu, 2002-03-21 at 15:40, Jon Baer wrote: > David Peterson wrote: > > > I've actually been working on an extension of Jaxen's XPath > > implementation to implement XPointer. This is partly where I'm coming > > Can you explain or show a little on how this would work? Ive been trying to > implement something very basic to connect 2 XML docs together, but after reading > the link u sent me, it looks like alot has to be taken into consideration. > > <link xlink:href="http://www.server.com/file.xml#xmlns(x=http://example.com/foo) > xmlns(y=http://example.org/bar)xpointer(//x:a/y:a)"/> > > Does that look right? Seems confusing. Ive just been doing something where > ElementHandler for dom4j pulls in a doc over the network and performs the handler > while it's coming in. Im trying to think why there is namespace declaration > inside the attributes ...
The reason for the namespace declarations is that the target document (http://www.server.com/file.xml) is apparently made up from at least two different namespaces. Once you add namespaces into the mix, an <a> attribute may not simply be an <a> anymore. Confusing, isn't it... Take for example, the following XML document: <x:root xmlns:x="http://example.org/foo" xlmns:y="http://example.org/bar"> <x:a> <y:a id="1"/> </x:a> <x:b> <y:a id="2"/> </x:b> <x:a> <y:a id="3"/> </x:a> </x:root> If you then try to retrieve all the <y:a> elements that are inside <x:a> elements, your XPath query would look like what is in the href above: "//x:a/y:a". Now, using Jaxen, you need to tell the XPath what you actually mean by "x" and "y", so you call the 'addNamespace()' method. the code will look like this: XPath xpath = new org.jaxen.jdom.XPath("//x:a/y:a"); // could be jdom, dom, dom4j, etc... xpath.addNamespace("x", "http://example.com/foo"); xpath.addNamespace("y", "http://example.org/bar"); List nodes = xpath.selectNodes( myDoc ); However, you could equally exchange "x" for "a" and "y" for "b", like this: XPath xpath = new org.jaxen.jdom.XPath("//a:a/b:a"); xpath.addNamespace("a", "http://example.com/foo"); xpath.addNamespace("b", "http://example.org/bar"); List nodes = xpath.selectNodes( myDoc ); And you will get exactly the same result - it is the namespace URI that is criticial, not the prefix. The prefix can be anything you like in the actual source document, as long as the namespace URIs match. So, what is happening in the XLink example you gave is that the URL is informing the XPointer processor (XPointer being an extension of XPath) what namespace each of the prefixes is actually referring to. You can think of the 'xmlns(x=http://example.com/foo)' and 'xmlns(y=http://example.org/bar)' statements basically equating to the 'xpath.addNamespace("x", "http://example.com/bar")' statements if you were writing it out in Java using Jaxen. Does that help? David _______________________________________________ Jaxen-interest mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jaxen-interest