You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Simon Stanlake <si...@tradebytes.com> on 2006/03/04 01:04:27 UTC

namespaces in root element of xsp generated page

Hi,
 
I've got an xsp page that I would like to have generate xml that looks
like the following...
 
<root xmlns:foo="http://www.foo.com">
    <data>hello</data>
</root>
 
Problem is i'd like to have the foo namespace be dynamic, ie: come from
a form variable or database or something. I can add dynamic namespace
declarations inside the body of the xml document by going
 
<root>
    <xsp:logic>
        this.contentHandler.startPrefixMapping(myprefix,myuri);
    </xsp:logic>
    <data>hello</data>
</root>
 
which will add a declaration inside the <data/> element, but any content
inside <xsp:logic/> tags that is outside the first non-xsp element will
not be executed inside the generate() function, so this technique does
not work with the root element.
 
Is there a way to add a dynamic namespace declaration to the root
element of an xsp-generated xml document? I've thought of intercepting
the contentHandler and replacing with my own that does a
startPrefixMapping() inside the body of startDocument, but I'm looking
for something easier first.
 
thanks in advance,
 
Simon 
 

Re: namespaces in root element of xsp generated page

Posted by Leszek Gawron <lg...@mobilebox.pl>.
Simon Stanlake wrote:
> Hi,
>  
> I've got an xsp page that I would like to have generate xml that looks 
> like the following...
>  
> <root xmlns:foo="http://www.foo.com">
>     <data>hello</data>
> </root>
>  
> Problem is i'd like to have the foo namespace be dynamic, ie: come from 
> a form variable or database or something. I can add dynamic namespace 
> declarations inside the body of the xml document by going
>  
> <root>
>     <xsp:logic>
>         this.contentHandler.startPrefixMapping(myprefix,myuri);
>     </xsp:logic>
>     <data>hello</data>
> </root>
>  
> which will add a declaration inside the <data/> element, but any content 
> inside <xsp:logic/> tags that is outside the first non-xsp element will 
> not be executed inside the generate() function, so this technique does 
> not work with the root element.
>  
> Is there a way to add a dynamic namespace declaration to the root 
> element of an xsp-generated xml document? I've thought of intercepting 
> the contentHandler and replacing with my own that does a 
> startPrefixMapping() inside the body of startDocument, but I'm looking 
> for something easier first.
>  
> thanks in advance,
>  
> Simon
>  
Have a look at cocoon-2.1.x\src\blocks\xsp\samples\java\cacheable.xsp. 
It shows the usage of how additional java code can be added under 
xsp:page/xsp:logic. This _might_ help.

-- 
Leszek Gawron                                      lgawron@mobilebox.pl
IT Manager                                         MobileBox sp. z o.o.
+48 (61) 855 06 67                              http://www.mobilebox.pl
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65

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