You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Mathias Schulze <MS...@web.de> on 2001/03/20 16:04:51 UTC

Please help

Hi all,

I have a problem, transforming two Strings(XML and XSL) to a HTML-String.
As I'm using my own XML and XSL String, I get an NullPointerExc. !
So I tryed the sample Files and the same Exception happens.

(I allready looked at the FAQ and so on at Apache's side!)

I have my own method 'contakt(URL)', that reads the Data from the URL and returns a string. That works well, because the XML comes from StoredProcedure and the XSL comes from a file, both from the Server.

Using 'System.out.println(contakt(XSLDATA));' shows a XSL-String!

Now a part of my listing:

synchronized (m_tfactory){
  StringReader sr = null;
  String string1, string2;
  StreamSource st = null;
  Templates tm = null;
  Templates templates=null;
  try{
       sr = new StringReader(contakt(XSLDATA));
     }
     catch (Exception e){System.out.println("error 1 " + e);}
  try{ 
       st = new StreamSource(sr);	
     }
     catch (Exception e){ System.out.println("error 2 " + e); }
     string2=st.toString();
  try{
       templates = m_tfactory.newTemplates(st); 
     }
     catch (Exception e){ System.out.println("error 3 " + e); }
// next line does the same, but isn't as easy to debug as the lines before
//Templates templates = m_tfactory.newTemplates(new StreamSource(new StringReader(contakt(XSLDATA))));
 Transformer transformer = templates.newTransformer();
 transformer.transform(new StreamSource(new StringReader(contakt(XMLDATA))), new StreamResult(pw)); //(new StreamSource(xmlbuf), new StreamResult(pw));
}
      System.out.println("Primed the pump!");
      this.showStatus("Ready to go!");
    }
    catch (Exception e)
    {
      this.showStatus("Could not prime the pump!");
      System.out.println("Could not prime the pump!");
      e.printStackTrace();
    }

The null Pointer exception happens at 'error 2' position.
Please write back.

Mathias

______________________________________________________________________________
Die Fachpresse ist sich einig: WEB.DE 20mal Testsieger! Kostenlos E-Mail, 
Fax, SMS, Verschlüsselung, POP3, WAP....testen Sie uns! http://freemail.web.de


Re: Please help

Posted by "Alex (???)" <al...@erp.ncu.edu.tw>.
hi Mathias:

u mentioned that u have own method to catch the xsl String , so it's my way
to try, and it's correct in the StreamSource.
so,u can put the xml string into here.

 transformer.transform(new StreamSource(new StringBufferInputStream(Yout XML
String Here)),new StreamResult(stringwriter));

hope this help !!!


IT DEP. Special Team-XML
       Alex
Tel:(03)4227151 ext:6024

alex@ERP.NCU.EDU.TW
=We Do Enterprise Services=
----- Original Message -----
From: "Mathias Schulze" <MS...@web.de>
To: <xa...@xml.apache.org>
Sent: Tuesday, March 20, 2001 11:04 PM
Subject: Please help


Hi all,

I have a problem, transforming two Strings(XML and XSL) to a HTML-String.
As I'm using my own XML and XSL String, I get an NullPointerExc. !
So I tryed the sample Files and the same Exception happens.

(I allready looked at the FAQ and so on at Apache's side!)

I have my own method 'contakt(URL)', that reads the Data from the URL and
returns a string. That works well, because the XML comes from
StoredProcedure and the XSL comes from a file, both from the Server.

Using 'System.out.println(contakt(XSLDATA));' shows a XSL-String!

Now a part of my listing:

synchronized (m_tfactory){
  StringReader sr = null;
  String string1, string2;
  StreamSource st = null;
  Templates tm = null;
  Templates templates=null;
  try{
       sr = new StringReader(contakt(XSLDATA));
     }
     catch (Exception e){System.out.println("error 1 " + e);}
  try{
       st = new StreamSource(sr);
     }
     catch (Exception e){ System.out.println("error 2 " + e); }
     string2=st.toString();
  try{
       templates = m_tfactory.newTemplates(st);
     }
     catch (Exception e){ System.out.println("error 3 " + e); }
// next line does the same, but isn't as easy to debug as the lines before
//Templates templates = m_tfactory.newTemplates(new StreamSource(new
StringReader(contakt(XSLDATA))));
 Transformer transformer = templates.newTransformer();
 transformer.transform(new StreamSource(new StringReader(contakt(XMLDATA))),
new StreamResult(pw)); //(new StreamSource(xmlbuf), new StreamResult(pw));
}
      System.out.println("Primed the pump!");
      this.showStatus("Ready to go!");
    }
    catch (Exception e)
    {
      this.showStatus("Could not prime the pump!");
      System.out.println("Could not prime the pump!");
      e.printStackTrace();
    }

The null Pointer exception happens at 'error 2' position.
Please write back.

Mathias

____________________________________________________________________________
__
Die Fachpresse ist sich einig: WEB.DE 20mal Testsieger! Kostenlos E-Mail,
Fax, SMS, Verschlüsselung, POP3, WAP....testen Sie uns!
http://freemail.web.de