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/05/28 08:48:40 UTC

Problem with namespaces jstl / xml

Hi all,

I've narrowed down the problem I had before with atom feeds not working, 
and it all seems to be due to the namespace declaration in the root element:

<feed version="0.3" xml:lang="en-US" xmlns="http://purl.org/atom/ns#">

This fails, and any x:out cannot see any elements (e.g. 
$doc/feed/@version) - presumably because xpath is looking for a 
particular namespace.

<feed version="0.3" xml:lang="en-US"> works fine.

Since there isn't a namespace prefix, what do I do? THis isdriving me 
potty, sinceI can't be the frist person with this problem.

Many thanks.

Digby


---------------------------------------------------------------------
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/>

Re: Problem with namespaces jstl / xml

Posted by Digby <li...@digby.net>.
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>.
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

Re: Dynamically adding components to pages

Posted by Rahul Akolkar <ra...@gmail.com>.
On 6/1/05, Marius Botha <ma...@workpool.co.za> wrote:
<snip/>
> I am using Tomcat 5 inside JBoss. What do you mean "(as a .tag impl)"? Where
> can I read more on how to do this?

Here is one reference [
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPTags5.html ]. Let me
know if you have specific questions.

-Rahul

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


RE: Dynamically adding components to pages

Posted by Marius Botha <ma...@workpool.co.za>.
>Can you use JSP 2.0 (if you're not already)? Tag files will give you the
>reuse you're talking about. Write a tag (as a .tag impl) that takes the
>task (or user) name as an attribute, and produces the appropriate controls
>(+ other presentation layer stuff around them). You can (re)use the custom
>tags you wrote in this tag file.

Thanks for responding.

I am using Tomcat 5 inside JBoss. What do you mean "(as a .tag impl)"? Where
can I read more on how to do this?

Cheers,

Marius



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


Re: Dynamically adding components to pages

Posted by Rahul P Akolkar <ak...@us.ibm.com>.
"Marius Botha" <ma...@workpool.co.za> wrote on 05/31/2005 06:43:33 AM:
<snip/>
> I have a requirement where my system needs to prompt users for certain
> information at certain times in a process. To do this I need to be able 
to
> add components to a page at run time based on a user's permissions. E.g. 
if
> the user is supposed to specify a date for the process to continue, I 
need
> to provide a calendar control; and if the user needs to enter a name, 
then
> provide a textbox. <snip/>

Sounds more like task dependent choices rather than user dependent ones. I 
guess thats an aside.

> I have developed my own custom tags that I would want to
> use but I have the following questions:
> 
> 1. How do I reuse my components in such an environment? I suppose I 
would
> need to provide a StringBuffer or something to my component to write to
> (how?) and then call the doStartTag(), etc. methods manually? <snip/>

Playing container is not a good thing.

> 2. How do I implement this in the JSP, seeing as the html/tags would 
have to
> be inserted at a certain stage. Has anyone done this before or can you 
give
> me any pointers?<snip/>

Can you use JSP 2.0 (if you're not already)? Tag files will give you the 
reuse you're talking about. Write a tag (as a .tag impl) that takes the 
task (or user) name as an attribute, and produces the appropriate controls 
(+ other presentation layer stuff around them). You can (re)use the custom 
tags you wrote in this tag file.

-Rahul

Dynamically adding components to pages

Posted by Marius Botha <ma...@workpool.co.za>.
Hi there,

Hope someone can help me.

I have a requirement where my system needs to prompt users for certain
information at certain times in a process. To do this I need to be able to
add components to a page at run time based on a user's permissions. E.g. if
the user is supposed to specify a date for the process to continue, I need
to provide a calendar control; and if the user needs to enter a name, then
provide a textbox. I have developed my own custom tags that I would want to
use but I have the following questions:

1. How do I reuse my components in such an environment? I suppose I would
need to provide a StringBuffer or something to my component to write to
(how?) and then call the doStartTag(), etc. methods manually?
2. How do I implement this in the JSP, seeing as the html/tags would have to
be inserted at a certain stage. Has anyone done this before or can you give
me any pointers?

Much appreciated.

Marius Botha


---------------------------------------------------------------------
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 Digby <li...@digby.net>.
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>

Many thanks.

Digby



Digby wrote:
> Hi all,
> 
> I've narrowed down the problem I had before with atom feeds not working, 
> and it all seems to be due to the namespace declaration in the root 
> element:
> 
> <feed version="0.3" xml:lang="en-US" xmlns="http://purl.org/atom/ns#">
> 
> This fails, and any x:out cannot see any elements (e.g. 
> $doc/feed/@version) - presumably because xpath is looking for a 
> particular namespace.
> 
> <feed version="0.3" xml:lang="en-US"> works fine.
> 
> Since there isn't a namespace prefix, what do I do? THis isdriving me 
> potty, sinceI can't be the frist person with this problem.
> 
> Many thanks.
> 
> Digby


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