You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Paul Wilson <pa...@gmail.com> on 2011/09/28 18:16:43 UTC

Using namespaces within XML documents produced from JSPXs

Hi there,

I'm trying use taglibs with a JSPX page, but also specify a namespace
declaration for elements rendered by the JSP. An example:

<foo:xyz xmlns:foo="path/to/foo/ns" xmlns:bar="path/to/bar/ns">
   <foo:p/>
   <bar:q/>
</foo:xyz>

In the above example, I have a taglib registered for only 'foo', whereas I'd
like 'bar' to be considered verbatim and added to the body content as such.
What actually happens is the xmlns declaration is removed and is not made
available to the taglib component processing 'foo:xyz'. Jasper then
complains that 'bar' is not bound.

I've also tried:

<jsp:root xmlns:jsp="..." version="2.1" xmlns:foo="path/to/foo/ns">
   <foo:xyz xmlns:bar="path/to/bar/ns">
         <foo:p/>
         <bar:q/>
   </foo:xyz>
</jsp:root>

But again the 'bar' namespace is removed. I also tried 'jsp:attribute',
although that appears to strip the namespace off the element completely,
despite http://java.net/jira/browse/JSP_SPEC_PUBLIC-97 stating that
namespaces would be supported in version 2.1.

I'm lost and can't think my way around this one unfortunately, any help
*vastly* appreciated.

Regards,
Paul

Re: Using namespaces within XML documents produced from JSPXs

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Paul,

On 9/29/2011 4:43 AM, Paul Wilson wrote:
> On 29 September 2011 09:28, Konstantin Kolinko
> <kn...@gmail.com>wrote:
>> 
>> The following will work for you:
>> 
>> <foo:xyz xmlns:foo="path/to/foo/ns"> <foo:p/> <bar:q
>> xmlns:bar="path/to/bar/ns" /> </foo:xyz>
> 
> 
> Unfortunately (this is the first thing I tried), the client won't
> accept the namespace being bound on the element itself, and
> requires that it be bound on the XML's root tag. Looks like I'm
> stuck.

Silly question: why not just do your own XML root tag?

<?xml version="1.0" encoding="UTF-8" ?>

<foo:xyz xmlns:foo="path/to/foo/ns" xmlns:bar="path/to/bar/ns">
  <real-foo-taglib:whatever>
      ...
  </real-foo-taglib:whatever>
  <bar:q />
</foo:xyz>

?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk6Ei54ACgkQ9CaO5/Lv0PCO2QCfYMhDvjiiiwPli2Nufy5fdTBT
WHIAn3S1QDb3XguxuwyeipBQ+uiOp0Wo
=NtJl
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Using namespaces within XML documents produced from JSPXs

Posted by Paul Wilson <pa...@gmail.com>.
On 29 September 2011 09:28, Konstantin Kolinko <kn...@gmail.com>wrote:
>
> The following will work for you:
>
> <foo:xyz xmlns:foo="path/to/foo/ns">
>   <foo:p/>
>  <bar:q xmlns:bar="path/to/bar/ns" />
> </foo:xyz>


Unfortunately (this is the first thing I tried), the client won't accept the
namespace being bound on the element itself, and requires that it be bound
on the XML's root tag. Looks like I'm stuck.

Thanks for your help, much appreciated!
Paul

Re: Using namespaces within XML documents produced from JSPXs

Posted by Konstantin Kolinko <kn...@gmail.com>.
2011/9/29 Paul Wilson <pa...@gmail.com>:
> On 28 September 2011 18:11, Konstantin Kolinko <kn...@gmail.com>wrote:
>
> This is what isn't working on Tomcat 6.0.32 for me. Note additionally that "
> http://www.w2.org/2000/svg" should be a taglib uri too to fully mirror my
> example. Perhaps I'm being too optimistic that the namespace attribute
> 'xmlns' would be made available to the custom tag??
>

As I wrote,  taglib can only generate text. It cannot generate
org.w3c.dom.Element.

The following will work for you:

<foo:xyz xmlns:foo="path/to/foo/ns">
  <foo:p/>
  <bar:q xmlns:bar="path/to/bar/ns" />
</foo:xyz>


Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Using namespaces within XML documents produced from JSPXs

Posted by Paul Wilson <pa...@gmail.com>.
On 28 September 2011 18:11, Konstantin Kolinko <kn...@gmail.com>wrote:
>
> 1) I replaced opening svg tag with:
>
> <svg xmlns="http://www.w3.org/2000/svg"
>     width="450" height="500" viewBox="0 0 450 500"
>     xmlns:c="http://java.sun.com/jsp/jstl/core"
>     xmlns:fn="http://java.sun.com/jsp/jstl/functions"
>     xmlns:jsp="http://java.sun.com/JSP/Page"
>     xmlns:foo="bar">
>  <jsp:directive.page contentType="image/svg+xml" />
>  <title>JSP 2.0 JSPX</title>
> <foo:x>Bar!</foo:x>
>
> Note xmlns declaration and foo:x element.
>
> The page,
> http://localhost:8080/examples/jsp/jsp2/jspx/textRotate.jspx?name=JSPX
> renders correctly and gives me:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <svg xmlns:foo="bar" xmlns="http://www.w3.org/2000/svg" viewBox="0 0
> 450 500" height="500" width="450"><title>JSP 2.0
> JSPX</title><foo:x>Bar!</foo:x><g id="testContent">(....)
>
>
> With correct xmlns:foo="bar" and <foo:x>Bar!</foo:x>.
>

This is what isn't working on Tomcat 6.0.32 for me. Note additionally that "
http://www.w2.org/2000/svg" should be a taglib uri too to fully mirror my
example. Perhaps I'm being too optimistic that the namespace attribute
'xmlns' would be made available to the custom tag??

Re: Using namespaces within XML documents produced from JSPXs

Posted by Konstantin Kolinko <kn...@gmail.com>.
2011/9/28 Konstantin Kolinko <kn...@gmail.com>:
> 2011/9/28 Paul Wilson <pa...@gmail.com>:
>> Hi there,
>>
>
> 1. What exactly build of Tomcat x.y.z  you are using?
>
>> I'm trying use taglibs with a JSPX page, but also specify a namespace
>> declaration for elements rendered by the JSP. An example:
>>
>> <foo:xyz xmlns:foo="path/to/foo/ns" xmlns:bar="path/to/bar/ns">
>>   <foo:p/>
>>   <bar:q/>
>> </foo:xyz>
>>
>> In the above example, I have a taglib registered for only 'foo', whereas I'd
>> like 'bar' to be considered verbatim and added to the body content as such.
>> What actually happens is the xmlns declaration is removed and is not made
>> available to the taglib component processing 'foo:xyz'. Jasper then
>> complains that 'bar' is not bound.
>>
>
> 2. What happens if you wrap all with <jsp:root> element and move your
> xmlns:bar there?
> (and not xmlns:foo like in your example below)
>
>> I've also tried:
>>
>> <jsp:root xmlns:jsp="..." version="2.1" xmlns:foo="path/to/foo/ns">
>>   <foo:xyz xmlns:bar="path/to/bar/ns">
>>         <foo:p/>
>>         <bar:q/>
>>   </foo:xyz>
>> </jsp:root>
>>
>
> 3. What version of specification is specified at the top of your web.xml file?


Just a quick test with current trunk of Tomcat:

Using the standard examples application that comes with Tomcat.
I edited the following page:
\webapps\examples\jsp\jsp2\jspx\textRotate.jspx

1) I replaced opening svg tag with:

<svg xmlns="http://www.w3.org/2000/svg"
     width="450" height="500" viewBox="0 0 450 500"
     xmlns:c="http://java.sun.com/jsp/jstl/core"
     xmlns:fn="http://java.sun.com/jsp/jstl/functions"
     xmlns:jsp="http://java.sun.com/JSP/Page"
     xmlns:foo="bar">
  <jsp:directive.page contentType="image/svg+xml" />
  <title>JSP 2.0 JSPX</title>
<foo:x>Bar!</foo:x>

Note xmlns declaration and foo:x element.

The page,
http://localhost:8080/examples/jsp/jsp2/jspx/textRotate.jspx?name=JSPX
renders correctly and gives me:

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns:foo="bar" xmlns="http://www.w3.org/2000/svg" viewBox="0 0
450 500" height="500" width="450"><title>JSP 2.0
JSPX</title><foo:x>Bar!</foo:x><g id="testContent">(....)


With correct xmlns:foo="bar" and <foo:x>Bar!</foo:x>.


2) But if I move xmlns declaration from <svg> element to the new
<jsp:root element> (adding it around the document):
<jsp:root version="2.2" xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:foo="bar">
<svg xmlns="http://www.w3.org/2000/svg"
     width="450" height="500" viewBox="0 0 450 500"
     xmlns:c="http://java.sun.com/jsp/jstl/core"
     xmlns:fn="http://java.sun.com/jsp/jstl/functions"
     >
  <jsp:directive.page contentType="image/svg+xml" />
  <title>JSP 2.0 JSPX</title>
<foo:x>Bar!</foo:x>

(...)
</jsp:root>

It generates invalid XML document where the foo prefix is not declared:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 450 500"
height="500" width="450"><title>JSP 2.0
JSPX</title><foo:x>Bar!</foo:x><g id="testContent"> (...)


So, from practical point of view, I think that the problem is the following:
- <jsp:root> tag by definition does not generate any content
- your custom tag can only generate text (from Tomcat perspective)

Thus it has no XML element in its possession to set xmlns attribute on it.
(Nor it is clever enough to add xmlns attribute to some other element,
as in the example of svg document it does not add it to the <svg>
element).

I think the cause for this behaviour might be that
the generated xml document can be included as a part into another xml
document (with <jsp:include>) and thus there should be a mechanism to
suppress unneeded xmlns declarations.

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Using namespaces within XML documents produced from JSPXs

Posted by Konstantin Kolinko <kn...@gmail.com>.
2011/9/28 Paul Wilson <pa...@gmail.com>:
> Hi there,
>

1. What exactly build of Tomcat x.y.z  you are using?

> I'm trying use taglibs with a JSPX page, but also specify a namespace
> declaration for elements rendered by the JSP. An example:
>
> <foo:xyz xmlns:foo="path/to/foo/ns" xmlns:bar="path/to/bar/ns">
>   <foo:p/>
>   <bar:q/>
> </foo:xyz>
>
> In the above example, I have a taglib registered for only 'foo', whereas I'd
> like 'bar' to be considered verbatim and added to the body content as such.
> What actually happens is the xmlns declaration is removed and is not made
> available to the taglib component processing 'foo:xyz'. Jasper then
> complains that 'bar' is not bound.
>

2. What happens if you wrap all with <jsp:root> element and move your
xmlns:bar there?
(and not xmlns:foo like in your example below)

> I've also tried:
>
> <jsp:root xmlns:jsp="..." version="2.1" xmlns:foo="path/to/foo/ns">
>   <foo:xyz xmlns:bar="path/to/bar/ns">
>         <foo:p/>
>         <bar:q/>
>   </foo:xyz>
> </jsp:root>
>

3. What version of specification is specified at the top of your web.xml file?

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org