users@jaxb.java.net

Re: Newbie Questions

From: Malachi de AElfweald <malachi_at_EOTI.ORG>
Date: Wed, 05 Mar 2003 18:30:18 -0700

I tried to use that idea, but not much luck. I think perhaps I needed more in my XSL.... I just copied your xsl code verbatim, and changed the url... I think I may have to add some apply-templates...

However, the code to use it is REALLY ugly anyways, since we are trying to do the marshalling, we don't have a file (unless I create a temp one) to do the transformation on, and thus have to pipe it.... Not a good solution...

 JAXBContext jc = JAXBContext.newInstance("com.temporalwave.jbase");
 final Marshaller m = jc.createMarshaller();
 JAXBResult result = new JAXBResult(jc);
 TransformerFactory tf = TransformerFactory.newInstance();
 Transformer t = tf.newTransformer(new StreamSource("fixns.xsl"));
 PipedWriter pipeOut = new PipedWriter();
 PipedReader pipeIn = new PipedReader(pipeOut);
 final PrintWriter writer = new PrintWriter(pipeOut);
 final Object obj = (Object)objex;
 Thread thread = new Thread()
 {
  public void run()
  {
   try{
    m.marshal(obj, writer);
      }catch(Exception e){
       System.out.println("Exception: " + e.getMessage());
       e.printStackTrace();
      }
  }
 };
 thread.start();
 t.transform(new StreamSource(pipeIn),result);
 System.out.println(result.getResult());