You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by John Keyes <jo...@yahoo.com> on 2001/05/01 16:19:30 UTC

Comments in a DOM

Hi,

I have a utility class that writes DOMs to Writers.  There are some
application specific data that I want to keep in comments in the
xml file.  The first time I run the utility the comments appear.  If
I run it a second time (still in the same JVM session) and reuse the
Transformer that I have then the comments are NOT present.  If I
create a new Transformer for each call then the comments are present.

Does anybody know why this behaviour exists.

Thanks a mil,
-John K


Re: Comments in a DOM

Posted by Gary L Peskin <ga...@firstech.com>.
Thanks for this info, John.  Could you please add this bug to bugzilla? 
I've verified that this is a problem and have been able to reproduce it.

Gary

John Keyes wrote:
> 
> The utility class is included below.  As you see the Transformer is
> a static member variable.  The if checks to see if the
> Transformer has been instantiated and if not then instantiate
> it.  If I remove the if and just create a new Transformer each
> time the behaviour is as I would expect with the comments appearing
> in the writer all the time.  When the if is in the code the comments
> appear the first time print is invoked but never subsequently.
> 
> ### SOF ###
> public class Dom2Writer {
>      /**
>       * The JAXP transformer factory
>       */
>      private static final TransformerFactory tfactory
>          = TransformerFactory.newInstance();
> 
>      /**
>       * The XSLT transformer
>       */
>      private static Transformer serializer;
> 
>      /**
>       * Prints the resulting document tree to the given output stream.
>       * @param   xmlDoc      - The XML Document tree
>       * @param   out         - The output stream to write the result to.
>       * @exception
>       */
>      public void print(Document xmlDoc,Writer out)
>          throws javax.xml.transform.TransformerException
>      {
>          if (serializer == null) {
>              try {
>                  serializer = tfactory.newTransformer();
>              }
>              catch (TransformerConfigurationException tce) {
>                  tce.printStackTrace(System.err);
>              }
>          }
> 
>          synchronized (serializer) {
> 
>              try {
>                  // Run the transformation
>                  serializer.transform(
>                      new DOMSource( xmlData ),
>                      new StreamResult( out )
>                  );
>              }
>              catch (TransformerException te) {
>                  te.printStackTrace(System.err);
>              }
>              catch(IllegalArgumentException ill) {
>                  ill.printStackTrace(System.err);
>              }
>          }
>      }
> }
> 
> ### EOF ###
> 
> -John K

Re: setting the value of xsl:variable - could not find more information

Posted by jason heddings <Ja...@Sun.COM>.
Ram-

The easiest way to do this is to use the "select" attribute for the
<xsl:variable .../> element.  Example:

<xsl:variable name="pi" select="/document/constants/pi-value" />

Or something similar.

HTH,
--jah

Ram Gajavelli wrote:
> 
> Hello,
> 
> Can somebody help me with the information about how to
> use a "xsl:variable" to be populated from the value of
> a given xml file so that I can use that variable in
> templates used on other elements.
> 
> Basically, setting the value of a defined variable to
> one of the elements' value and then be able to use it
> in the templates that will be called later.
> 
> Thanks,
> ..Ram.
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/

-- 

 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      \\\|///                 Jason Heddings             ((
     \\ ~ ~ //                303.272.5166 (x75166)    C|~~|
     (/ @ @ /)                Jason.Heddings@Sun.COM    `__'
 ~~oOOo~(_)~oOOo~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

setting the value of xsl:variable - could not find more information

Posted by Ram Gajavelli <rg...@yahoo.com>.
Hello,

Can somebody help me with the information about how to
use a "xsl:variable" to be populated from the value of
a given xml file so that I can use that variable in
templates used on other elements.

Basically, setting the value of a defined variable to
one of the elements' value and then be able to use it
in the templates that will be called later.

Thanks,
..Ram.

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Re: Memory problems when using Xalan extension Redirect

Posted by Will Raymond <wr...@tibco.com>.
http://nagoya.apache.org/bugzilla/buglist.cgi?bug_status=NEW&bug_status=ASSI
GNED&bug_status=REOPENED&email1=&emailtype1=substring&emailassigned_to1=1&em
ail2=eric@tibco&emailtype2=substring&emailreporter2=1&bugidtype=include&bug_
id=&changedin=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&short_desc=&s
hort_desc_type=substring&long_desc=&long_desc_type=substring&bug_file_loc=&b
ug_file_loc_type=substring&keywords=&keywords_type=anywords&field0-0-0=noop&
type0-0-0=noop&value0-0-0=&cmdtype=doit&order=%27Importance%27

----- Original Message -----
From: "Ram Gajavelli" <rg...@yahoo.com>
To: <xa...@xml.apache.org>
Sent: Tuesday, May 01, 2001 11:26 AM
Subject: Re: Memory problems when using Xalan extension Redirect


> Thanks for the response. But could you please give me
> more details as where I can find it.
> --- Will Raymond <wr...@tibco.com> wrote:
> > You might want to look at a patch submitted by
> > eric@tibco.com.
> >
> > ----- Original Message -----
> > From: "Ram Gajavelli" <rg...@yahoo.com>
> > To: <xa...@xml.apache.org>
> > Sent: Tuesday, May 01, 2001 11:22 AM
> > Subject: Memory problems when using Xalan extension
> > Redirect
> >
> >
> > > I am using Xalan extension Redirect to split a
> > given
> > > Xml file into many files according to a Xsl file.
> > The
> > > issue I am running into is the JVM is running out
> > of
> > > memory and system hangs up.
> > >
> > > I have three such huge Xml files being processed
> > in
> > > three different threads and make around 500 Meg of
> > > data all three included. I thought as Redirect
> > class
> > > uses SAX Parser, it should be okay.
> > >
> > > Any insight into this is appreciated.
> > >
> > > Thanks,
> > > Ram.
> > >
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Yahoo! Auctions - buy the things you want at great
> > prices
> > > http://auctions.yahoo.com/
> > >
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/
>


Re: Memory problems when using Xalan extension Redirect

Posted by Ram Gajavelli <rg...@yahoo.com>.
Thanks for the response. But could you please give me
more details as where I can find it.
--- Will Raymond <wr...@tibco.com> wrote:
> You might want to look at a patch submitted by
> eric@tibco.com.
> 
> ----- Original Message ----- 
> From: "Ram Gajavelli" <rg...@yahoo.com>
> To: <xa...@xml.apache.org>
> Sent: Tuesday, May 01, 2001 11:22 AM
> Subject: Memory problems when using Xalan extension
> Redirect 
> 
> 
> > I am using Xalan extension Redirect to split a
> given
> > Xml file into many files according to a Xsl file.
> The
> > issue I am running into is the JVM is running out
> of
> > memory and system hangs up.
> > 
> > I have three such huge Xml files being processed
> in
> > three different threads and make around 500 Meg of
> > data all three included. I thought as Redirect
> class
> > uses SAX Parser, it should be okay. 
> > 
> > Any insight into this is appreciated.
> > 
> > Thanks,
> > Ram.
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Yahoo! Auctions - buy the things you want at great
> prices
> > http://auctions.yahoo.com/
> > 
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Re: Memory problems when using Xalan extension Redirect

Posted by Will Raymond <wr...@tibco.com>.
You might want to look at a patch submitted by eric@tibco.com.

----- Original Message ----- 
From: "Ram Gajavelli" <rg...@yahoo.com>
To: <xa...@xml.apache.org>
Sent: Tuesday, May 01, 2001 11:22 AM
Subject: Memory problems when using Xalan extension Redirect 


> I am using Xalan extension Redirect to split a given
> Xml file into many files according to a Xsl file. The
> issue I am running into is the JVM is running out of
> memory and system hangs up.
> 
> I have three such huge Xml files being processed in
> three different threads and make around 500 Meg of
> data all three included. I thought as Redirect class
> uses SAX Parser, it should be okay. 
> 
> Any insight into this is appreciated.
> 
> Thanks,
> Ram.
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/
> 


Memory problems when using Xalan extension Redirect

Posted by Ram Gajavelli <rg...@yahoo.com>.
I am using Xalan extension Redirect to split a given
Xml file into many files according to a Xsl file. The
issue I am running into is the JVM is running out of
memory and system hangs up.

I have three such huge Xml files being processed in
three different threads and make around 500 Meg of
data all three included. I thought as Redirect class
uses SAX Parser, it should be okay. 

Any insight into this is appreciated.

Thanks,
Ram.

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Re: Comments in a DOM

Posted by Gary L Peskin <ga...@firstech.com>.
John Keyes wrote:
> 
> The utility class is included below.  As you see the Transformer is
> a static member variable.  The if checks to see if the
> Transformer has been instantiated and if not then instantiate
> it.  If I remove the if and just create a new Transformer each
> time the behaviour is as I would expect with the comments appearing
> in the writer all the time.  When the if is in the code the comments
> appear the first time print is invoked but never subsequently.

John --

I'll have a look a little later in the day.  Just a note, though, you
may end up creating multiple serializers since your

  if (serializer == null)

is not synchronized.

Gary

Re: Comments in a DOM

Posted by John Keyes <jo...@yahoo.com>.
The utility class is included below.  As you see the Transformer is
a static member variable.  The if checks to see if the
Transformer has been instantiated and if not then instantiate
it.  If I remove the if and just create a new Transformer each
time the behaviour is as I would expect with the comments appearing
in the writer all the time.  When the if is in the code the comments
appear the first time print is invoked but never subsequently.

### SOF ###
public class Dom2Writer {
     /**
      * The JAXP transformer factory
      */
     private static final TransformerFactory tfactory
         = TransformerFactory.newInstance();

     /**
      * The XSLT transformer
      */
     private static Transformer serializer;

     /**
      * Prints the resulting document tree to the given output stream.
      * @param   xmlDoc      - The XML Document tree
      * @param   out         - The output stream to write the result to.
      * @exception
      */
     public void print(Document xmlDoc,Writer out)
         throws javax.xml.transform.TransformerException
     {
         if (serializer == null) {
             try {
                 serializer = tfactory.newTransformer();
             }
             catch (TransformerConfigurationException tce) {
                 tce.printStackTrace(System.err);
             }
         }

         synchronized (serializer) {

             try {
                 // Run the transformation
                 serializer.transform(
                     new DOMSource( xmlData ),
                     new StreamResult( out )
                 );
             }
             catch (TransformerException te) {
                 te.printStackTrace(System.err);
             }
             catch(IllegalArgumentException ill) {
                 ill.printStackTrace(System.err);
             }
         }
     }
}

### EOF ###

-John K


Re: Comments in a DOM

Posted by Gary L Peskin <ga...@firstech.com>.
John Keyes wrote:
> 
> Hi,
> 
> I have a utility class that writes DOMs to Writers.  There are some
> application specific data that I want to keep in comments in the
> xml file.  The first time I run the utility the comments appear.  If
> I run it a second time (still in the same JVM session) and reuse the
> Transformer that I have then the comments are NOT present.  If I
> create a new Transformer for each call then the comments are present.
> 
> Does anybody know why this behaviour exists.
> 
> Thanks a mil,
> -John K

John --

I think we'd need to see your java code along with any input files to
understand exactly what you're talking about.  There's just not enough
information in your posting itself.

Gary