You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Rajesh Aravindakshan <ar...@yahoo.com> on 2005/04/14 16:49:31 UTC
Transform Custom Generated Output
Hi,
I am able to get an xml output from a custom
generator.It displays in the browser as XML tree. But,
I am not able to transform the output with an xsl
stylesheet. It displays the data as text.
What am I doing wrong. Please help. Thank you.
Here is my sitemap:
<map:match pattern="mygenerator.xml">
<map:generate type="mygenerator">
<map:parameter name="use-request-parameters"
value="true"/>
</map:generate>
<map:transform src="stylesheets/test.xsl"/>
<map:serialize type="html"/>
</map:match>
------------------------------
Here is my custom generator code.
(Sorry for the long code)
public class MyGenerator extends AbstractGenerator {
Request request = null;
Enumeration paramNames = null;
public void setup(SourceResolver resolver, Map
OjectModel,String src, Parameters par)
throws ProcessingException, SAXException,
IOException {
public void generate () throws IOException,
SAXException, ProcessingException {
try{
SAXParserFactory spf =
SAXParserFactory.newInstance();
spf.setValidating(false);
SAXParser saxParser = spf.newSAXParser();
// create an XML reader
XMLReader reader = saxParser.getXMLReader();
String message = getResponse();
reader.setContentHandler(super.xmlConsumer);
reader.parse(new InputSource(new
StringReader(message)));
} catch(Exception e){}
/*XMLReader xmlreader =
SAXReaderFactory.createXMLReader();
xmlreader.setContentHandler(super.xmlConsumer);
InputSource source = new InputSource(new
StringReader(message));
xmlreader.parse(source);*/
}
private String getResponse() {
String xmlResponse = new String();
String inputLine;
String urlstr =
"http://srv/cgi-bin/cgiip.exe/getxml.p";
String str = "?";
try{
URL url = new URL(urlstr);
URLConnection connection = url.openConnection();
BufferedReader in = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
while ((inputLine = in.readLine()) != null) {
if (xmlResponse==null) xmlResponse = new
String();
xmlResponse = xmlResponse + inputLine;
} // while
in.close();
} catch(Exception e){
System.out.println("ERROR WHILE CONNECTION: " +
e.toString());
return
"<response><status>ERROR</status></response>";
}
return xmlResponse;
}
Thanks in advance.
Rajesh Aravindakshan
Regards,
Rajesh Aravindakshan
__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Transform Custom Generated Output
Posted by Jorg Heymans <jh...@domek.be>.
try serializing as xml instead of html, most browser will indent the
output nicely then.
Rajesh Aravindakshan wrote:
> Hi,
> I am able to get an xml output from a custom
> generator.It displays in the browser as XML tree. But,
> I am not able to transform the output with an xsl
> stylesheet. It displays the data as text.
> What am I doing wrong. Please help. Thank you.
>
> Here is my sitemap:
> <map:match pattern="mygenerator.xml">
> <map:generate type="mygenerator">
> <map:parameter name="use-request-parameters"
> value="true"/>
> </map:generate>
> <map:transform src="stylesheets/test.xsl"/>
> <map:serialize type="html"/>
> </map:match>
> ------------------------------
> Here is my custom generator code.
> (Sorry for the long code)
>
> public class MyGenerator extends AbstractGenerator {
>
> Request request = null;
> Enumeration paramNames = null;
>
>
> public void setup(SourceResolver resolver, Map
> OjectModel,String src, Parameters par)
> throws ProcessingException, SAXException,
> IOException {
>
> public void generate () throws IOException,
> SAXException, ProcessingException {
> try{
> SAXParserFactory spf =
> SAXParserFactory.newInstance();
> spf.setValidating(false);
> SAXParser saxParser = spf.newSAXParser();
> // create an XML reader
> XMLReader reader = saxParser.getXMLReader();
>
> String message = getResponse();
> reader.setContentHandler(super.xmlConsumer);
> reader.parse(new InputSource(new
> StringReader(message)));
> } catch(Exception e){}
> /*XMLReader xmlreader =
> SAXReaderFactory.createXMLReader();
> xmlreader.setContentHandler(super.xmlConsumer);
> InputSource source = new InputSource(new
> StringReader(message));
> xmlreader.parse(source);*/
> }
>
>
> private String getResponse() {
> String xmlResponse = new String();
> String inputLine;
>
> String urlstr =
> "http://srv/cgi-bin/cgiip.exe/getxml.p";
> String str = "?";
>
> try{
> URL url = new URL(urlstr);
> URLConnection connection = url.openConnection();
> BufferedReader in = new BufferedReader(new
> InputStreamReader(connection.getInputStream()));
>
>
> while ((inputLine = in.readLine()) != null) {
> if (xmlResponse==null) xmlResponse = new
> String();
> xmlResponse = xmlResponse + inputLine;
> } // while
>
> in.close();
> } catch(Exception e){
> System.out.println("ERROR WHILE CONNECTION: " +
> e.toString());
> return
> "<response><status>ERROR</status></response>";
> }
>
> return xmlResponse;
> }
>
> Thanks in advance.
> Rajesh Aravindakshan
>
> Regards,
> Rajesh Aravindakshan
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Small Business - Try our new resources site!
> http://smallbusiness.yahoo.com/resources/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org