passing xml stream to xalan

Discussion in 'XML' started by Sandy, Aug 12, 2005.

  1. Sandy

    Sandy Guest

    Hi,

    I have some data stored in my internal data structure. I am writing this
    data in an xml file and invoking xalan on this file to perform some
    transformation.
    After the transformation I want to put the data in Database so i m reading
    the xml produced by xalan.

    But as there are lot of IO operations so the application is very slow.
    Is there any way to pass the xml stream (using the string buffer that I am
    writing into XML file) directly to xalan

    can somebody give me an example code.

    Thanks in advance
     
    Sandy, Aug 12, 2005
    #1
    1. Advertising

  2. Hello Sandy,

    Answering in reverse order:

    > But as there are lot of IO operations so the application is very slow.
    > Is there any way to pass the xml stream (using the string buffer that I am
    > writing into XML file) directly to xalan
    >


    From the string buffer construct a Reader and use
    this in the StreamSource constructor.

    StringBuffer sb= ....;
    Transformer t= TransformerFactory.newInstance().newTransformer();
    t.transform(new StreamSource(new StringReader(sb.toString()), "buffer:sb"),
    new StreamResult(new File("output.xml")));

    While this avoids disk-io, it does not avoid the parsing/lexical
    analysis overhead.

    > I have some data stored in my internal data structure. I am writing this
    > data in an xml file and invoking xalan on this file to perform some
    > transformation.


    A more efficient technique could be to generate SAX ContentHandler
    events as you traverse your internal data structure. You could
    then feed this contentHandler into the SAXSource constructor:

    Class DSToXML implements ContentHandler ....;
    DSToXML reporter;
    t.transform(new SAXSource(reporter), ...);

    Hope this gives you a start,

    Nigel
     
    Nigel Whitaker, Aug 15, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. satish mn via JavaKB.com
    Replies:
    0
    Views:
    423
    satish mn via JavaKB.com
    Nov 25, 2004
  2. RC
    Replies:
    6
    Views:
    651
    Martin Honnen
    Apr 22, 2005
  3. hongping
    Replies:
    1
    Views:
    754
    hongping
    Nov 2, 2003
  4. RoyalDutchman
    Replies:
    0
    Views:
    402
    RoyalDutchman
    Dec 17, 2003
  5. cvissy
    Replies:
    0
    Views:
    624
    cvissy
    Nov 16, 2004
Loading...

Share This Page