John,
        I have not looked at that, but I certainly will now. Thank you
for pointing that out!

-Dan Feather

-----Original Message-----
From: John Gentilin [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, June 21, 2005 4:16 PM
To: Dan Feather
Cc: [email protected]
Subject: Re: Custom XMLReader: I must be missing something?

Dan,

Have you looked into using the SQL Extensions. The SQL Extension, in 
streaming mode,
creates a window where the DTM object only exists for the current row 
being fetched.
This is much more memory efficient and probably faster than creating a 
SAX filter. More
memory efficient because memory usage is totally deterministic, it uses 
the same amount of
memory if the query is 1 row or 1 million rows. Faster because the 
transformation starts
as soon as the first row is transfered from the DB rather than waiting 
for all the rows to be
read and converted to the DTM object.

Regards
John G

Dan Feather wrote:

>Hello,
>       I have looked through the mailing list archives and I have seen
>threads where people have had similar problems, but I haven't read
>anything that jumped out at me as an answer to my problem.
>
>       I have a simple XMLReader that opens a connection to a data
>base, and generates SAX events for the rows in a result set... I am
>piping the events through a TransformerHandler but I am not getting
what
>I think I should get. I have a feeling it has something to do with my
>namespace (or lack of one) but I am not sure how to go about fixing it
>if that is the case. Here is the parse method from my XMLReader:
>
>---------------------------------SNIP---------------------------------
>public void parse(DbInputSource input) throws IOException, SAXException
>{
>  //If we don't have a handler, we don't need to do anything.
>  if(docHandler == null)return;
>
>  Attributes EMPTY_ATTR = new AttributesImpl();
>               
>  Connection con = input.getConnection();
>  String query = input.getQuery();
>  Statement stmt = null;
>  try{
>    stmt = con.createStatement();
>    ResultSet rs = stmt.executeQuery(query);
>    ResultSetMetaData rsmd = rs.getMetaData();
>               
>    int columns = rsmd.getColumnCount();
>    docHandler.startDocument();
>    docHandler.startElement("","table","table",EMPTY_ATTR);
>    while(rs.next()){
>      docHandler.startElement("","row","row",EMPTY_ATTR);
>      for(int i = 1; i <= columns; i++){
>        String colName = rsmd.getColumnName(i);
>        String value = rs.getString(i);
>        docHandler.startElement("",colName,colName,EMPTY_ATTR);
>        docHandler.characters(value.toCharArray(),0,value.length());
>        docHandler.endElement("",colName,colName);
>      }
>      docHandler.endElement("","row","row");
>    }
>    docHandler.endElement("","table","table");
>    docHandler.endDocument();
>  }
>  catch(Exception e){
>    e.printStackTrace();
>  }
>  finally{
>    try{
>      stmt.close();
>    }
>    catch(Exception e){}
>    try{
>      con.close();
>    }
>    catch(Exception e){}
>  }
>}
>---------------------------------SNIP---------------------------------
>
>So I then use that parser in a simple test program like the following:
>---------------------------------SNIP---------------------------------
>try {
>  TransformerFactory tFactory = TransformerFactory.newInstance();
>  if(tFactory.getFeature(SAXSource.FEATURE) &&
>tFactory.getFeature(SAXResult.FEATURE)){
>                       
>    SAXTransformerFactory saxTFactory =(SAXTransformerFactory)tFactory;
>                               
>    //TransformerHandler tHandler =
saxTFactory.newTransformerHandler();
>    TransformerHandler tHandler = saxTFactory.newTransformerHandler(new
>StreamSource("test2.xsl"));
>                       
>    XMLDBSaxParser parser = new XMLDBSaxParser();
>    parser.setContentHandler(tHandler);
>
> 
>//parser.setProperty("http://xml.org/sax/properties/lexical-handler",tH
a
>ndler);
>                               
>    Serializer serializer =
>SerializerFactory.getSerializer(OutputPropertiesFactory.getDefaultMetho
d
>Properties("xml"));
>
>    serializer.setOutputStream(System.out);
>    tHandler.setResult(new SAXResult(serializer.asContentHandler()));
>                               
>    // Parse the XML input document.
>    DbInputSource input = new DbInputSource();
>    input.setQuery("select * from foo.bar");
>    parser.parse(input);       
>  }
>}
>catch (Exception e) {
>  e.printStackTrace();
>}
>---------------------------------SNIP---------------------------------
>
>I am using a simple stylesheet right now for testing (test2.xsl). When
I
>do the following I get output:
><xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform";
>version = "1.0" >
>  <xsl:output method = "xml" />
>  <xsl:template match = "/" >
>    <Test>
>      <xsl:apply-templates select = "//row" />
>    </Test>
>  </xsl:template>
>
>  <xsl:template match = "row" >
>      <xsl:value-of select="name()" />
>  </xsl:template>
></xsl:stylesheet>
>
>I end up with <Test>rowrowrowrowrowrowrow...</Test>, which is what it
>should do. However, when I add start and end tags (<test1> and
</test1>)
>in the template for "row" no output is produced at all:
>
><xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform";
>version = "1.0" >
>  <xsl:output method = "xml" />
>  <xsl:template match = "/" >
>    <Test>
>      <xsl:apply-templates select = "//row" />
>    </Test>
>  </xsl:template>
>
>  <xsl:template match = "row" >
>    <test1>
>      <xsl:value-of select="name()" />
>    </test1>
>  </xsl:template>
></xsl:stylesheet>
>
>I have a feeling I am not generating the events correctly. Can anyone
>give me an idea as to what I am doing wrong? I have found examples that
>do the same thing I am doing above, but they are 1 or 2 years old so I
>figure something may have changed and I am not finding it. I appreciate
>your help!
>
>-Dan Feather
>  
>





NOTICE: This electronic mail message and any files transmitted with it are 
intended exclusively for the individual or entity to which it is addressed. The 
message, together with any attachment, may contain confidential and/or 
privileged information. Any unauthorized review, use, printing, saving, 
copying, disclosure or distribution is strictly prohibited. If you have 
received this message in error, please immediately advise the sender by reply 
email and delete all copies.



Reply via email to