You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Lionel Crine <cr...@4dconcept.fr> on 2003/02/04 11:15:08 UTC

Custom transformer

I have an xml document :

<?xml version="1.0" encoding="UTF-8"?>
<xsp:page xmlns:xsp="http://apache.org/xsp" 
xmlns:my_NS="http://www.my_NS.com/my_NS/query/1.0">


<my_NS:document>
   <my_NS:query VERSION="2.0" RESULTSPACE="R1">
     <my_NS:property NAME = "DocType">
       <my_NS:elem>DOCUMENT</my_NS:elem>
     </my_NS:property>
   </my_NS:query>
</my_NS:document>

</xsp:page>


In my transformer I need to get all that si between "<my_NS:document> 
</my_NS:document>" tag and put it in a string or a String buffer.

Which method can do that for me ?

Sax "Characters" method only returns  DOCUMENT, but I also need the tags.

Lionel


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: Custom transformer

Posted by Lionel Crine <cr...@4dconcept.fr>.
I saw that and I've already implemented this method.

Where I'm stuck is that these methods return a "void" so how can I store my 
tags and text in a StringBuffer?

Lionel


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


RE: Custom transformer

Posted by Lionel Crine <cr...@4dconcept.fr>.
I see, thanks


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


RE: Custom transformer

Posted by Carsten Ziegeler <cz...@s-und-n.de>.

> -----Original Message-----
> From: Konstantin Piroumian [mailto:kpiroumian@apache.org]
> Sent: Tuesday, February 04, 2003 11:42 AM
> To: cocoon-users@xml.apache.org
> Subject: Re: Custom transformer 
> 
> 
> From: "Lionel Crine" <cr...@4dconcept.fr>
> 
> > I have an xml document :
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xsp:page xmlns:xsp="http://apache.org/xsp"
> > xmlns:my_NS="http://www.my_NS.com/my_NS/query/1.0">
> >
> >
> > <my_NS:document>
> >    <my_NS:query VERSION="2.0" RESULTSPACE="R1">
> >      <my_NS:property NAME = "DocType">
> >        <my_NS:elem>DOCUMENT</my_NS:elem>
> >      </my_NS:property>
> >    </my_NS:query>
> > </my_NS:document>
> >
> > </xsp:page>
> >
> >
> > In my transformer I need to get all that si between "<my_NS:document>
> > </my_NS:document>" tag and put it in a string or a String buffer.
> >
> > Which method can do that for me ?
> 
> You should implement almost all the methods of ContentHandler interface,
> such as:
> startDocument()
> startElement()
> characters()
> endElement()
> endDocument()
> 
> etc. and store everything you need into a String buffer.
> 
> For an example you can take a look at classes in
> src/java/org/apache/cocoon/transformation/helper/ package.

If you inherit from the AbstractSAXTransformer, you only have
to invoke startSerializedXMLRecording() before the first element
arrives that you want to have included in your string.

And at the end invoke endSerializedXMLRecording() and you get
all the XML inbetween as a string.

Have a look at some other transformers using the AbstractSAXTransformer
for samples.

Carsten

---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: Custom transformer

Posted by Konstantin Piroumian <kp...@apache.org>.
From: "Lionel Crine" <cr...@4dconcept.fr>

> I have an xml document :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsp:page xmlns:xsp="http://apache.org/xsp"
> xmlns:my_NS="http://www.my_NS.com/my_NS/query/1.0">
>
>
> <my_NS:document>
>    <my_NS:query VERSION="2.0" RESULTSPACE="R1">
>      <my_NS:property NAME = "DocType">
>        <my_NS:elem>DOCUMENT</my_NS:elem>
>      </my_NS:property>
>    </my_NS:query>
> </my_NS:document>
>
> </xsp:page>
>
>
> In my transformer I need to get all that si between "<my_NS:document>
> </my_NS:document>" tag and put it in a string or a String buffer.
>
> Which method can do that for me ?

You should implement almost all the methods of ContentHandler interface,
such as:
startDocument()
startElement()
characters()
endElement()
endDocument()

etc. and store everything you need into a String buffer.

For an example you can take a look at classes in
src/java/org/apache/cocoon/transformation/helper/ package.

-- Konstantin

>
> Sax "Characters" method only returns  DOCUMENT, but I also need the tags.
>
> Lionel
>
>
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>
> To unsubscribe, e-mail:     <co...@xml.apache.org>
> For additional commands, e-mail:   <co...@xml.apache.org>
>
>


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>