You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Digby <li...@digby.net> on 2005/06/01 21:55:49 UTC

Re: Problem with namespaces jstl / xml

Thanks for your help, but jstl doesn't seem to work like that. Don't 
know why, but you can't put namespaceprefixes in the xpath.



Rahul P Akolkar wrote:
> news <ne...@sea.gmane.org> wrote on 05/31/2005 05:52:18 AM:
> 
> 
>>I guess this is a namespace-uri issue, after lots of digging around.
>>
>>Please could someone explain what my xpath should be to output the 
>>version number of the following (atom) xml (either in JSTL or plain old 
>>xpath? I just can't get it.
>>
>><feed version="0.3" xml:lang="en-US" xmlns="http://purl.org/atom/ns#">
>></feed>
> 
> <snip/>
> 
> Assuming you have a document whose namespace URI(s) you do not know (or 
> worse, keep changing), it is common to explicitly bind these to namespace 
> prefixes so that the expanded names are in accordance with the XPath "data 
> model". In your case, you can try this (untested):
> 
> <code-fragment>
> // Say 'document' holds the Document object
> Element root = (Element) document.getDocumentElement();
> String my_ns = root.getAttribute("xmlns");
> root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:myns", my_ns);
> String xpath_ver = "/myns:feed/@version";
> Node ver = XPathAPI.selectSingleNode(root, xpath_ver, root);
> // ver.getNodeValue() should give you the version number, as a String
> 
> // Likewise, this should get you the <entry> elements:
> String xpath_entry = "/myns:feed/myns:entry";
> NodeList items = XPathAPI.selectNodeList(root, xpath_entry, root);
> // You can now iterate over the <entry> items found
> </code-fragment>
> 
> I am not aware of a solution based purely on JSTL's XML taglib.
> 
> -Rahul
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: Problem with namespaces jstl / xml

Posted by Rahul P Akolkar <ak...@us.ibm.com>.
You could (depending on how urgent this is):
a) Dig into the Taglibs JSTL (standard) impl, file an enhancement request 
if you're convinced enough
b) Wait for one of the jstl spec public's owners (Dhiru, Justyna, Pierre) 
to respond
c) Author custom tag(s) with Java impls that suit your needs (we know its 
doable using the APIs)

-Rahul

news <ne...@sea.gmane.org> wrote on 06/01/2005 03:55:49 PM:

> Thanks for your help, but jstl doesn't seem to work like that. Don't 
> know why, but you can't put namespaceprefixes in the xpath.
> 
<snip/>